Skip to content

/cheatsheets/npm/npm-cheat-sheet

npm cheat sheet: install, run, update, publish

verified onenvironmentlocal · windows 10.0.26200 arm64 · GNU bash 5.3.15 (Git Bash) · 11.19.0updated 2026-10-20
tool
npm
versions
npm 10, npm 11
os
any

The npm commands you use every week, grouped by task.

Project setup

bash
npm init -y >/dev/null
npm pkg set description="demo" scripts.hello="echo hello from npm run"
npm pkg get name description
npm run hello --silent

Output

{
  "name": "work",
  "description": "demo"
}
hello from npm run

Install and remove

CommandWhat it does
npm installinstall everything in package.json
npm install pkgadd pkg to dependencies
npm install -D pkgadd pkg to devDependencies
npm install pkg@1.2.3install an exact version
npm install -E pkgsave the exact version instead of a ^ range
npm uninstall pkgremove pkg and its entry in package.json
npm ciclean install from package-lock.json (CI)
npm install -g pkginstall a command-line tool globally

Inspect

CommandWhat it does
npm ls pkgwhere pkg is in the dependency tree
npm explain pkgwhy pkg is installed
npm outdatedinstalled vs wanted vs latest
npm view pkg versionsevery published version
npm view pkg peerDependenciespeer ranges of the latest version
npm auditknown vulnerabilities

Update

CommandWhat it does
npm updateupdate within the ranges in package.json
npm update pkgupdate one package within its range
npm install pkg@latestmove to the latest version, changing the range

Scripts

CommandWhat it does
npm runlist scripts
npm run buildrun the build script
npm run test -- --watchpass extra arguments after --
npm test / npm startshortcuts for the test and start scripts
npx toolrun a binary from node_modules/.bin, or download it once

Config and cache

CommandWhat it does
npm config listeffective configuration
npm config set key value --location projectwrite to the project .npmrc
npm config get registrycurrent registry URL
npm cache verifycheck the cache and remove garbage

Sources