elefcode
← All cheat sheets

Tools

npm Cheat Sheet — Command Reference

Everyday npm commands for managing dependencies and running project scripts.

Advertisement

Installing

npm installInstall everything in package.json
npm install pkgAdd a dependency
npm install -D pkgAdd a dev dependency
npm install -g pkgInstall globally
npm install [email protected]Install a specific version
npm ciClean install from the lockfile (for CI)
npm uninstall pkgRemove a package

Scripts

npm run <script>Run a script from package.json
npm startShorthand for the start script
npm testShorthand for the test script
npm runList all available scripts
npx <pkg>Run a package without installing it

Info & updates

npm list --depth=0List top-level installed packages
npm outdatedShow packages with newer versions
npm updateUpdate within the allowed semver range
npm view pkg versionsList all published versions
npm auditCheck for known vulnerabilities
npm audit fixAuto-fix vulnerabilities where possible

Versioning & publishing

npm version patchBump the patch version and tag it
npm version minor|majorBump the minor or major version
npm publishPublish the package to the registry
npm publish --access publicPublish a scoped package publicly

Semver ranges

^1.2.3Allow minor and patch updates (1.x.x)
~1.2.3Allow patch updates only (1.2.x)
1.2.3Exactly this version
*Any version (avoid)

More cheat sheets