Skip to main content

npm Cheatsheet

By Dejan Panovski Updated on Download PDF

Quick reference for npm commands for project setup, dependency management, scripts, updates, and package inspection

npm is the default package manager for Node.js. This cheatsheet covers common npm commands for starting projects, installing dependencies, running scripts, updating packages, inspecting dependency trees, and maintaining package metadata.

Project Setup

Create and inspect project metadata.

CommandDescription
npm initCreate package.json interactively
npm init -yCreate package.json with defaults
npm pkg get namePrint package name
npm pkg set scripts.start="node index.js"Add or update a script
npm pkg delete scripts.oldRemove a package.json field

Install Dependencies

Add project, development, and global packages.

CommandDescription
npm installInstall project dependencies
npm install packageInstall and save dependency
npm install -D packageInstall development dependency
npm install -g packageInstall global CLI package
npm install package@1.2.3Install a specific version
npm install package@latestInstall latest published version
npm install --no-save packageInstall without saving

Clean Installs

Reproduce dependency trees from lock files.

CommandDescription
npm ciClean install from package-lock.json
npm ci --omit=devInstall production dependencies only
npm install --omit=devSkip development dependencies
npm install --package-lock-onlyUpdate lock file only
npm install --ignore-scriptsInstall without lifecycle scripts

Versions and Updates

Check outdated packages and update dependency ranges.

CommandDescription
npm outdatedShow packages with newer versions
npm updateUpdate within package.json ranges
npm update packageUpdate one package
npm view package versionShow latest package version
npm view package versionsList published versions
npm version patchBump package patch version
npm version minorBump package minor version

Remove and Clean

Uninstall packages and clear generated files.

CommandDescription
npm uninstall packageRemove dependency
npm uninstall -D packageRemove development dependency
npm uninstall -g packageRemove global package
npm pruneRemove extraneous packages
npm dedupeReduce duplicate dependencies
npm cache verifyVerify npm cache
npm cache clean --forceClear npm cache

Scripts and Execution

Run package scripts and one-off tools.

CommandDescription
npm runList available scripts
npm run scriptRun a named script
npm startRun the start script
npm testRun the test script
npm run build -- --watchPass args to script
npx packageRun package binary once
npm create vite@latest appRun create package

Inspect Packages

List dependencies and package metadata.

CommandDescription
npm listList direct dependencies
npm list --allList full dependency tree
npm list -g --depth=0List global packages
npm explain packageExplain why package is installed
npm rootShow local node_modules path
npm root -gShow global node_modules path

Configuration

View and change npm settings.

CommandDescription
npm config listShow current config
npm config get prefixShow global install prefix
npm config set prefix ~/.npm-globalSet global install prefix
npm config get registryShow registry URL
npm config set registry urlSet registry URL
npm whoamiShow logged-in npm user
npm loginLog in to npm registry

Security and Audit

Check dependency risks and funding metadata.

CommandDescription
npm auditScan dependencies for advisories
npm audit fixApply compatible security fixes
npm audit --omit=devAudit production dependencies
npm fundShow funding links
npm doctorCheck npm environment
npm pingTest registry connection

Use these references for Node.js and package workflows.

GuideDescription
npm CommandFull npm tutorial with examples
Install Node.js on Ubuntu 26.04Install Node.js and npm
Install Yarn on Ubuntu 20.04Alternative package manager