← Back to Home

npm Cheat Sheet

Essential Node Package Manager commands

npm init
Initialize a new package.json file. Use -y to accept all defaults quickly.

npm init -y

Keywords: initialize, package, json, project, setup

npm install
Install all dependencies listed in package.json. Creates node_modules folder and package-lock.json.

npm install

Keywords: install, dependencies, modules, packages

npm install <package>
Install a specific package. Use --save-dev for development dependencies, -g for global installation.

npm install express --save-dev

Keywords: install, package, dependency, global, dev

npm uninstall
Remove a package from dependencies. Use -g to uninstall globally installed packages.

npm uninstall lodash

Keywords: uninstall, remove, package, dependency

npm update
Update packages to their latest versions within semver constraints. Updates package-lock.json.

npm update

Keywords: update, upgrade, latest, version

npm run
Execute scripts defined in package.json. List available scripts with npm run without arguments.

npm run build

Keywords: run, script, execute, build, start

npm start
Run the start script defined in package.json. Shorthand for npm run start.

npm start

Keywords: start, run, server, application

npm test
Run the test script defined in package.json. Shorthand for npm run test.

npm test

Keywords: test, testing, run, spec

npm list
Display installed packages in tree format. Use --depth=0 for top-level only, -g for global packages.

npm list --depth=0

Keywords: list, installed, packages, tree, dependencies

npm outdated
Check for outdated packages. Shows current, wanted, and latest versions.

npm outdated

Keywords: outdated, check, versions, update

npm audit
Scan for security vulnerabilities in dependencies. Use --fix to automatically fix issues.

npm audit --fix

Keywords: audit, security, vulnerabilities, fix

npm publish
Publish package to npm registry. Requires authentication and proper package.json configuration.

npm publish

Keywords: publish, registry, package, release

npm version
Bump package version. Use patch, minor, or major for semantic versioning.

npm version patch

Keywords: version, bump, semver, patch, minor, major

npm cache
Manage npm cache. Use clean to clear cache, verify to check cache integrity.

npm cache clean --force

Keywords: cache, clean, clear, verify

npm config
Manage npm configuration. Set registry, proxy, or other npm settings.

npm config set registry https://registry.npmjs.org/

Keywords: config, configuration, registry, settings

npm link
Create symbolic link for local development. Link packages for testing before publishing.

npm link

Keywords: link, symbolic, local, development, testing

npm search
Search npm registry for packages. Find packages by name or keywords.

npm search express

Keywords: search, find, packages, registry

npm info
Display detailed information about a package. Shows versions, dependencies, and metadata.

npm info express

Keywords: info, information, package, details, metadata

npm ci
Clean install from package-lock.json. Faster and more reliable for CI/CD environments.

npm ci

Keywords: ci, clean, install, production, lock

npm prune
Remove extraneous packages not listed in package.json. Clean up node_modules folder.

npm prune

Keywords: prune, remove, extraneous, clean, modules