- List of
commands
npm
ornpm help
- Display full usage info of all commands
npm -l
- Display usage info of specific command
$ npm <command> -h
- Write scripts to run in
package.json
file
"scripts": {
"lint": "./node_modules/.bin/eslint"
}
npm list -g
npm ls -g --depth=0
- When you run prune, the npm CLI will run through your
package.json
and compare it to your project’s/node_modules
directory. It will print a list of modules that aren’t in yourpackage.json
. npm prune
- Initializes project as a node project
- Will ask you a bunch of questions, and then write a package.json for you.
npm init
npm install <package name>
npm i <package name>
npm init --yes
will install defaults
- The
--save
option instructs NPM to include the package inside of the dependencies section of your package.json npm install --save
npm install -S
npm i -S
npm install --save-dev
npm install -D
npm i -D
npm install <package name@<version number>
- Example:
npm install underscore@1.8.2
npm update
npm update <package name>
npm outdated
npm outdated -g
npm uninstall <package name>
npm r <package name> --save
npm r <package name> --save-dev
npm uninstall <package name> --save-dev
npm uninstall <package name> -g
npm config list
npm config get prefix
- When npm installs a package it keeps a copy, so the next time you want to install that package, it doesn’t need to hit the network. The copies are cached in the .npm directory in your home path.
- This directory will get cluttered with old packages over time, so it’s useful to clean it up occasionally.
npm cache clean
npm test
npm t