/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
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 --silentOutput
{
"name": "work",
"description": "demo"
}
hello from npm runInstall and remove
| Command | What it does |
|---|---|
| npm install | install everything in package.json |
| npm install pkg | add pkg to dependencies |
| npm install -D pkg | add pkg to devDependencies |
| npm install pkg@1.2.3 | install an exact version |
| npm install -E pkg | save the exact version instead of a ^ range |
| npm uninstall pkg | remove pkg and its entry in package.json |
| npm ci | clean install from package-lock.json (CI) |
| npm install -g pkg | install a command-line tool globally |
Inspect
| Command | What it does |
|---|---|
| npm ls pkg | where pkg is in the dependency tree |
| npm explain pkg | why pkg is installed |
| npm outdated | installed vs wanted vs latest |
| npm view pkg versions | every published version |
| npm view pkg peerDependencies | peer ranges of the latest version |
| npm audit | known vulnerabilities |
Update
| Command | What it does |
|---|---|
| npm update | update within the ranges in package.json |
| npm update pkg | update one package within its range |
| npm install pkg@latest | move to the latest version, changing the range |
Scripts
| Command | What it does |
|---|---|
| npm run | list scripts |
| npm run build | run the build script |
| npm run test -- --watch | pass extra arguments after -- |
| npm test / npm start | shortcuts for the test and start scripts |
| npx tool | run a binary from node_modules/.bin, or download it once |
Config and cache
| Command | What it does |
|---|---|
| npm config list | effective configuration |
| npm config set key value --location project | write to the project .npmrc |
| npm config get registry | current registry URL |
| npm cache verify | check the cache and remove garbage |
Sources
Related pages
commands · npmnpm install a specific version: npm install package@versionInstall an exact version with npm install package@1.2.3, a range with package@^1.2, or a dist-tag with package@next. List published versions with npm view.compare · npmnpm ci vs npm install: differences and when to use eachnpm ci installs exactly what package-lock.json says, deletes node_modules first and never edits the lockfile; npm install resolves ranges and may update it.flags · npmnpm install --legacy-peer-deps: what it does and when to use it--legacy-peer-deps makes npm skip installing and checking peer dependencies, as npm 6 did, so ERESOLVE conflicts no longer stop the install. Risks and fixes.