npm Cheat Sheet
The default Node package manager — install, audit, ci, scripts, workspaces, and publishing.
Installing
9npm installInstall from package-lock (write lock if missing)
npm ciClean install exactly per lockfile
npm install PACKAGEInstall and save a dependency
npm install -D PACKAGEDev dependency
npm install -g PACKAGEGlobal install
npm install PACKAGE@^2Ranged version
npm pruneRemove extraneous packages
npm ls --depth=0Top-level installed tree
npm ls PACKAGEWhy is it installed / version
Publishing
6npm version patchBump version + git tag
npm publishPublish the package
npm publish --tag nextPublish under a dist-tag
npm unpublish PACKAGE@VERRemove a version (timed)
npm dist-tag add PACKAGE@ver latestMove the latest tag
npm packBuild the tarball locally
Scripts & Project
7npm runList available scripts
npm run buildRun a script
npm run build -- --watchPass flags to a script
npm init -yScaffold package.json
npm config get registryCurrent registry
npm exec PACKAGERun a package's binary (npx)
npm dedupeCollapse duplicate versions
Audit & Maintenance
6npm auditVulnerability report
npm audit fixAuto-fix safe upgrades
npm audit fix --forceMajor bumps (can break)
npm outdatedOutdated direct deps
npm updateUpdate within ranges
npm view PACKAGE versionLatest published version
Workspaces
4"workspaces": ["packages/*"]Monorepo layout
npm install -w packages/app PACKAGEInstall into one workspace
npm run build --workspacesRun a script everywhere
npm ls --workspacesCross-workspace tree