Skip to content
We are what we repeatedly do.
Excellence, then, is not an act, but a habit
Aristotle

Npm cheatsheet

Few npm commands I found very useful during development.

Command Description
npm -v show current npm version installed
npm init inizialize npm project into the current folder, creates package.json
npm --help show npm help manual page
npm list show a tree of every package found in the current folder
npm list -g same as above ^^, but search also in global packages
npm list -g --depth=0 same as above ^^, but do not show every package’s dependencies
npm list [package name] show a tree of every instance found in the current folder of that specific package
npm install install all packages in package.json
npm install [package name] install a package as dependency*
npm install [package name] --save install a package as dependency (same as above)
npm install [package name] --save-dev install a package as dev dependency
npm install --save username/repo#branch-name-or-commit-or-tag install package from GitHub repository
npm uninstall [package name] uninstall a package
npm update update top level packages
npm update --depth [number of levels] update dependencies of dependencies packages
npm update [package name] -g update global package installation
npm docs [package name] show README, official website, of the given package
npm outdated show packages that should be updated

🧨 !important
By default, in node@5 the --save flag is implicit.

Therefore running these two commands you will have the same result:

npm i lodash

# is the same as
npm i lodash --save

they add a new line in your package.json into the dependecies object:

{
"name": "test-project",
"version": "1.0.0",
"description": "",
"main": "index.js",
"scripts": {
"test": "echo \"Error: no test specified\" && exit 1"
},
"author": "Giulia Chiola",
"license": "ISC",
"dependencies": {
"lodash": "^4.17.21"
}
}

Aliases #

Alias Command
npm i npm install
npm i [package name] -D npm install [package name] --save-dev
npm ls npm list
npm up [package name] npm update [package name]
npm un [package name] npm uninstall [package name]

Config #

Set initial values for npm projects:

npm config set init-author-name "Your name"
npm config set init-author-email "your@email.com"
npm config set init-license MIT

⚡️ Bonus tip #

npm-check is a useful tool to check for outdated, incorrect, and unused dependencies

📚 More info

View on GitHub

Comment on DEV.to or Hashnode

Take me to the next post!