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 packages in my node.js projects:
-
npm init: Inside the command prompt the user is guided with questions and creates a new package.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 (in the working current directory) and updates the list of dependencies in the package.json file.
-
npm install –save-dev PACKAGE_NAME: Installs the most recend 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. packages are installed globally so that their commands can be used from every other project, for example the gulp 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 in package.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 use npm list and see the same results as with npm ls. With npm 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 outdated: The command goes through the dependencies defined in your package.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.