npm Commands Cheatsheet

Complete npm CLI reference: install, scripts, publishing, workspaces, and more

The npm commands cheatsheet is a complete reference for the npm CLI: installing packages, managing scripts, publishing, workspaces, auditing, and more. Search by command or description, copy any example with one click.

How to Use This npm Commands Cheatsheet

npm (Node Package Manager) is the default package manager for Node.js. This cheatsheet covers every npm command you'll use regularly, from basic package installation to publishing your own packages.

Installing Packages

Use npm install (or npm i) to install packages. Add -D for devDependencies (test/build tools), -g for global tools. Use npm ci in CI/CD for reproducible installs from lock file.

Running Scripts

Define scripts in package.json under "scripts". Run with npm run <name>. The start, test, and build scripts can be run without "run": npm start, npm test.

npx for One-Off Commands

npx runs packages without installing them globally. Ideal for scaffolding tools: npx create-react-app, npx prettier --write ..

Security Auditing

Run npm audit to check for known vulnerabilities. Use npm audit fix to auto-fix compatible updates, or npm audit fix --force for breaking changes.

Frequently Asked Questions

Is this npm cheatsheet free?

Yes, completely free with no signup required. All content runs in your browser.

What is the difference between npm install --save and --save-dev?

--save (or -S) adds to dependencies (required at runtime). --save-dev (or -D) adds to devDependencies (only needed during development: testing, building, linting). In npm 5+, --save is the default, so npm install package automatically saves to dependencies.

What is npx and when should I use it?

npx runs npm packages without installing them globally. It downloads and runs the specified package temporarily. Use it for one-off commands: npx create-react-app, npx prettier --write ., npx @11ty/eleventy. Also useful for running package binaries: npx eslint src/.

How do npm workspaces work?

Workspaces let you manage multiple packages in a single repository (monorepo). Add a workspaces field in root package.json pointing to package directories. npm install at the root installs all dependencies and hoists shared packages. Run scripts across workspaces with npm run build --workspaces.

What does npm ci do differently than npm install?

npm ci (clean install) installs exact versions from package-lock.json, deletes node_modules first, and fails if lock file is out of sync. It's faster and deterministic — ideal for CI/CD pipelines. npm install updates lock file and resolves ranges. Use npm ci in production builds.