NPM Cheat Sheet
COMMAND
DESCRIPTION
- |npm init|Create package.json interactively.
- |npm init -y|Create package.json with defaults.
- |npm install|Install all dependencies.
- |npm install pkg|Install a pkg as a dependency.
- |npm install -D pkg|Install a pkg as a dev dependency.
- |npm install -g pkg|Install a package globally.
- |npm install pkg@1.2.3|Install a specific version.
- |npm ci|Clean install from lockfile.
- |npm uninstall pkg|Remove a package.
- |npm uninstall -g pkg|Remove a global package.
- |npm update|Update packages to latest allowed.
- |npm update pkg|Update a specific package.
- |npm outdated|Show packages with newer versions.
- |npm run script|Run an npm script.
- |npm start|Run the start script.
- |npm test|Run the test script.
- |npm run script -- --flag|Pass extra args to a script.
- |npm list|List installed packages (local).
- |npm list -g|List globally installed packages.
- |npm list --depth=0|List top-level packages only.
- |npm info pkg|Show pkg metadata from registry.
- |npm search term|Search the npm registry.
- |npm view pkg versions|List all published versions.
- |npm audit|Check for known vulnerabilities.
- |npm audit fix|Auto-fix vulnerabilities.
- |npm dedupe|Remove duplicate packages.
- |npm prune|Remove pkg not in package.json.
- |npm rebuild|Rebuild native packages.
- |npm cache clean --force|Clear the npm cache.
- |npm doctor|Check the npm environment.
- |npm login|Authenticate with the registry.
- |npm logout|Log out of the registry.
- |npm whoami|Show the logged-in user.
- |npm publish|Publish package to the registry.
- |npm unpublish pkg|Remove a published package.
- |npm pack|Create a tarball of the package.
- |npm link|Symlink package for local dev.
- |npm link pkg|Use a locally linked package.
- |npm version patch|Bump patch version.
- |npm version minor|Bump minor version.
- |npm version major|Bump major version.
- |npm config list|Show current npm configuration.
- |npm config set key val|Set a config value.
- |npm config get key|Get a config value.
- |npm exec pkg|Run a package bin (prefers local).
- |npm pkg get key|Read a field from package.json.
- |npm pkg set key=val|Write a field to package.json.
- |npm explain pkg|Show why a package is installed.
- |npx pkg|Run a package without installing.
- |npx pkg@ver|Run a specific version with npx.