Tutorial by Examples

Introduction Package is a term used by npm to denote tools that developers can use for their projects. This includes everything from libraries and frameworks such as jQuery and AngularJS to task runners such as Gulp.js. The packages will come in a folder typically called node_modules, which will a...
# Set the repository for the scope "myscope" npm config set @myscope:registry http://registry.corporation.com # Login at a repository and associate it with the scope "myscope" npm adduser --registry=http://registry.corporation.com --scope=@myscope # Install a package &quo...
To uninstall one or more locally installed packages, use: npm uninstall <package name> The uninstall command for npm has five aliases that can also be used: npm remove <package name> npm rm <package name> npm r <package name> npm unlink <package name> npm un ...
Before publishing a package you have to version it. npm supports semantic versioning, this means there are patch, minor and major releases. For example, if your package is at version 1.2.3 to change version you have to: patch release: npm version patch => 1.2.4 minor release: npm version min...
Node.js package configurations are contained in a file called package.json that you can find at the root of each project. You can setup a brand new configuration file by calling: npm init That will try to read the current working directory for Git repository information (if it exists) and enviro...
First, make sure that you have configured your package (as said in Setting up a package configuration​). Then, you have to be logged in to npmjs. If you already have a npm user npm login If you don't have a user npm adduser To check that your user is registered in the current client npm co...
You may define scripts in your package.json, for example: { "name": "your-package", "version": "1.0.0", "description": "", "main": "index.js", "author": "", "license": &qu...
To remove extraneous packages (packages that are installed but not in dependency list) run the following command: npm prune To remove all dev packages add --production flag: npm prune --production More on it
To generate a list (tree view) of currently installed packages, use npm list ls, la and ll are aliases of list command. la and ll commands shows extended information like description and repository. Options The response format can be changed by passing options. npm list --json json - Sh...
Since npm itself is a Node.js module, it can be updated using itself. If OS is Windows must be running command prompt as Admin npm install -g npm@latest If you want to check for updated versions you can do: npm outdated In order to update a specific package: npm update <package name>...
By default, npm installs the latest available version of modules according to each dependencies' semantic version. This can be problematic if a module author doesn't adhere to semver and introduces breaking changes in a module update, for example. To lock down each dependencies' version (and the ve...
You can use npm install -g to install a package "globally." This is typically done to install an executable that you can add to your path to run. For example: npm install -g gulp-cli If you update your path, you can call gulp directly. On many OSes, npm install -g will attempt to writ...
Building project dependencies can sometimes be a tedious task. Instead of publishing a package version to NPM and installing the dependency to test the changes, use npm link. npm link creates a symlink so the latest code can be tested in a local environment. This makes testing global tools and proje...

Page 1 of 1