Quick reference

NPM Command Cheat Sheet

npm dependency installation, reproducible builds, scripts and package version ranges.

· Published · Updated

Scope. npm CLI 11. Registry, ownership and deprecation commands require appropriate account permissions. npm version can update files and create a Git commit/tag; review the working tree first.

For dependency resolution, lockfiles, npm versus pnpm and undeclared dependencies, see the Node.js package management reference.

Package management

Command Description
npm i Alias for npm install
npm install Install project dependencies from package.json
npm install --omit=dev Install dependencies while omitting development dependencies

Adding packages

Command Description
npm install lodash Install a package
npm install --save-dev lodash Save as a development dependency
npm install --save-exact lodash Save an exact version

Listing packages

Command Description
npm list Show installed project dependencies
npm list -g --depth 0 Show top-level globally installed packages
npm view lodash version Show the registry version of a named package
npm outdated Show outdated project dependencies

Updating

Command Description
npm update Update local dependencies within version ranges
npm update --include=dev Include development dependencies when updating
npm update -g Update global packages
npm update lodash Update a named package

Removing packages

Command Description
npm rm lodash Remove a dependency

More commands

Package specifications

Command Description
npm i sax Registry package
npm i sax@latest Use the latest tag
npm i lodash@4.17.21 Use version 4.17.21
npm i sax@">=1 <2.0" Use a version range
npm i @org/sax Scoped registry package
npm i user/repo GitHub
npm i user/repo#master GitHub
npm i github:user/repo GitHub
npm i gitlab:user/repo GitLab
npm i /path/to/repo Absolute local path
npm i ./archive.tgz Local tarball
npm i https://site.com/archive.tgz Remote tarball

Bumping versions

Command Description
npm version 1.2.3 Set the package version to 1.2.3
npm version major Increment the major version: 1.2.3 to 2.0.0
npm version minor Increment the minor version: 1.2.3 to 1.3.0
npm version patch Increment the patch version: 1.2.3 to 1.2.4

Other commands

# Add someone as an owner
npm owner add USERNAME PACKAGENAME
# list packages
npm ls
# Adds warning to those that install a package of old versions
npm deprecate PACKAGE@"< 0.2.0" "critical bug fixed in v0.2.0"
# update all packages, or selected packages
npm update [-g] PACKAGE
# Check for outdated packages
npm outdated [PACKAGE]

Reproducible installation

npm ci

Requires an existing lockfile matching package.json. It removes node_modules before installation and does not rewrite the lockfile. Keep dependency-tree options consistent with those used to create the lockfile.

Reference

npm CLI.

Related topics