A list of helpful and often used commands of the npm package directory
The following list contains npm commands that I use practically every day while working with npm packages in my node.js projects:
-
npm init
While using the command prompt the user is guided with a number questions in order to create a newpackage.json
file. The command is very useful when starting a new node.js project. -
npm install
Installs locally, in the current directory, all the modules that are listed as dependencies in the package.json file. -
npm install --save <package-name>
Installs the most recent version of the specified package locally and updates the list of dependencies in thepackage.json
file. -
npm install --save-dev <package-name>
Installs the most recent version of the specified package locally as a development only package. This means that the code of the package is only required during the development of your web application and will not be included in any production code. -
npm install -g <package-name>
Installs a package globally. Such packages make their commands available to every project using npm, for example thegulp
plugin. -
npm link <package-name>
Links the specified global package in the node_modules folder of your working directory, so that other packages working with the specified package do not have to create any separate local copy. -
npm remove --save <package-name>
Removes a package from the current directory and also removes it’s reference from the dependencies inpackage.json
file. -
npm dedupe
Npm tries to normalize the dependencies of the installed packages and remove the ones that are used multiple times. This command can be especially useful in Windows environments where the allowed path of a folder is limited to 260 characters. -
npm view <package-name> version
See the version of an installed package. -
npm ls
Lists the installed packages and their versions in the current directory. You can also usenpm list
and see the same results as withnpm ls
. Withnpm list -g
you can see a list with the globally installed plugins. -
npm uninstall <package-name>
Uninstalls the specified package from your current directory. -
npm cache clean
Mostly used when we have problems with installing or updating packages because of corrupted temporary files. -
npm dedupe
Tries to normalize the modules hierarchy inside thenode_modules
path. -
npm outdated
The command goes through the dependencies defined in yourpackage.json
file and points out the modules that could be updated. Take a look at the following example:
Feel free to write a comment about commands that are not in this list, so that I add them into the article.