npm Cheat Sheet

The default Node package manager — install, audit, ci, scripts, workspaces, and publishing.

Build & Package5 sections · 32 commands
⌘K

Installing

9
npm install

Install from package-lock (write lock if missing)

npm ci

Clean install exactly per lockfile

npm install PACKAGE

Install and save a dependency

npm install -D PACKAGE

Dev dependency

npm install -g PACKAGE

Global install

npm install PACKAGE@^2

Ranged version

npm prune

Remove extraneous packages

npm ls --depth=0

Top-level installed tree

npm ls PACKAGE

Why is it installed / version

Publishing

6
npm version patch

Bump version + git tag

npm publish

Publish the package

npm publish --tag next

Publish under a dist-tag

npm unpublish PACKAGE@VER

Remove a version (timed)

npm dist-tag add PACKAGE@ver latest

Move the latest tag

npm pack

Build the tarball locally

Scripts & Project

7
npm run

List available scripts

npm run build

Run a script

npm run build -- --watch

Pass flags to a script

npm init -y

Scaffold package.json

npm config get registry

Current registry

npm exec PACKAGE

Run a package's binary (npx)

npm dedupe

Collapse duplicate versions

Audit & Maintenance

6
npm audit

Vulnerability report

npm audit fix

Auto-fix safe upgrades

npm audit fix --force

Major bumps (can break)

npm outdated

Outdated direct deps

npm update

Update within ranges

npm view PACKAGE version

Latest published version

Workspaces

4
"workspaces": ["packages/*"]

Monorepo layout

npm install -w packages/app PACKAGE

Install into one workspace

npm run build --workspaces

Run a script everywhere

npm ls --workspaces

Cross-workspace tree