npm Commands

npm commands cheatsheet.

Install, run, manage and publish — the npm commands you use every day. Tap to copy.

Installing
npm initCreate a package.json interactively
npm init -yCreate a package.json with defaults
npm installInstall all dependencies from package.json
npm install <pkg>Add a package as a dependency
npm install -D <pkg>Add a package as a dev dependency
npm install -g <pkg>Install a package globally
npm uninstall <pkg>Remove a package
Running scripts
npm startRun the start script
npm testRun the test script
npm run <script>Run a custom script from package.json
npm run buildRun the build script
npx <pkg>Run a package binary without installing it
Managing
npm updateUpdate packages within allowed ranges
npm outdatedShow packages with newer versions available
npm list --depth=0List top-level installed packages
npm auditCheck dependencies for known vulnerabilities
npm audit fixAutomatically fix vulnerable dependencies
npm cache clean --forceClear the npm cache
Publishing
npm loginAuthenticate with the npm registry
npm version patchBump the patch version and tag it
npm publishPublish the package to the registry
npm packCreate a tarball without publishing

From install to publish

Whether you're starting a project with npm init, adding packages with npm install, running tasks with npm run, or shipping with npm publish, these are the commands that come up constantly. npx is the handy one people forget — it runs a package's binary without installing it.

FAQ

What's the difference between npm install -D and -g?
-D (--save-dev) adds the package as a dev dependency for that project only; -g installs it globally on your machine so its command is available everywhere.
What does npx do?
npx runs a package's executable without permanently installing it — great for one-off tools like npx create-react-app.

More cheatsheets