Command Line
NPM Cheatsheet
Quick reference for package installs, script executions, versions, and config.
Initialization & Config
5npm init Initialize a new package.json file interactively.
npm init -y Initialize a new package.json with default options.
npm config list List NPM configuration options.
npm config set registry <url> Change package download registry URL.
npm whoami Display logged-in username on registry.
Installing Dependencies
6npm install Install all dependencies listed in package.json (alias: npm i).
npm install <package> Install a package and save it under dependencies.
npm install <package> --save-dev Install package under devDependencies (alias: npm i -D).
npm install <package> --global Install package globally on system (alias: npm i -g).
npm install <package>@<version> Install a specific version of a package.
npm ci Clean install dependencies matching package-lock.json exactly (for CI/CD).
Updating & Removing
5npm uninstall <package> Remove a package from node_modules and package.json (alias: npm un).
npm update Update all installed packages to latest semver matching version range.
npm update <package> Update a specific package.
npm outdated Check registry to see if any installed packages are outdated.
npm prune Remove packages not listed in package.json from node_modules.
Scripts & Execution
4npm run <script-name> Execute a command script defined in package.json.
npm start Shortcut to run npm run start.
npm test Shortcut to run npm run test.
npx <command> Download and execute a package binary without installing it globally.
Cache & Audits
4npm audit Audit dependencies for known security vulnerabilities.
npm audit fix Automatically fix vulnerabilities by updating dependencies.
npm cache clean --force Clear NPM local packet download cache.
npm cache verify Verify health of local packet cache.
Publishing
3npm login Login to registry using username, password, and OTP.
npm publish Publish current package folder to npm registry.
npm version <patch/minor/major> Bump package version and update git tag.
NPM Package Manager Cheatsheet
NPM (Node Package Manager) is the default package manager for the JavaScript runtime environment Node.js. This searchable reference covers package installation, dependency management, script runs, versioning, and package publishing.
Frequently Asked Questions
What is the difference between npm install and npm ci?
npm install (npm i) reads package.json, installs packages, and may update package-lock.json if version constraints permit.
npm ci (Clean Install) reads package-lock.json directly and installs dependencies matching it exactly, deleting node_modules first. It is faster and perfect for CI environments.
What is npx?
npx is a CLI utility shipped with NPM since v5.2.0. It executes packages from the npm registry directly without requiring global installation on your local machine (e.g. npx -y create-vite-app@latest).