DEV Community

Giulia Chiola
Giulia Chiola

Posted on • Edited on • Originally published at giuliachiola.dev

7 3

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
Enter fullscreen mode Exit fullscreen mode

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"
  }
}
Enter fullscreen mode Exit fullscreen mode

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
Enter fullscreen mode Exit fullscreen mode

⚡️ Bonus tip

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

📚 More info

AWS Security LIVE!

Join us for AWS Security LIVE!

Discover the future of cloud security. Tune in live for trends, tips, and solutions from AWS and AWS Partners.

Learn More

Top comments (0)

Billboard image

The Next Generation Developer Platform

Coherence is the first Platform-as-a-Service you can control. Unlike "black-box" platforms that are opinionated about the infra you can deploy, Coherence is powered by CNC, the open-source IaC framework, which offers limitless customization.

Learn more

👋 Kindness is contagious

Please leave a ❤️ or a friendly comment on this post if you found it helpful!

Okay