- List of
commandsnpmornpm 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.jsonfile
"scripts": {
"lint": "./node_modules/.bin/eslint"
}npm list -gnpm ls -g --depth=0
- When you run prune, the npm CLI will run through your
package.jsonand compare it to your project’s/node_modulesdirectory. 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 --yeswill install defaults
- The
--saveoption instructs NPM to include the package inside of the dependencies section of your package.json npm install --savenpm install -Snpm i -S
npm install --save-devnpm install -Dnpm i -D
npm install <package name@<version number>- Example:
npm install [email protected]
npm updatenpm update <package name>
npm outdatednpm outdated -g
npm uninstall <package name>npm r <package name> --savenpm 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 testnpm t