npm Install & Dependencies

Install, update, remove, lockfile, and local-development npm dependency workflows.

View
StandardDetailedCompact
Export
Copy the compact sheet, download it, or print it.
Download
`D` dense toggle · `C` copy all

Installing dependencies

Install packages in different dependency buckets.

Install a package

Install a runtime dependency.

bashANYnpminstalldeps
bash
npm install <package>

Install a runtime dependency.

Install a specific version

Install an exact version.

bashANYnpminstallversion
bash
npm install <package>@<version>

Install an exact version.

Install a dev dependency

Add a development dependency.

bashANYnpminstalldevdependency
bash
npm install -D <package>

Add a development dependency.

Install an optional dependency

Add an optional dependency.

bashANYnpminstalloptional
bash
npm install -O <package>

Add an optional dependency.

Install as peer dependency

Add a peer dependency entry.

bashANYnpminstallpeer
bash
npm install -P <package>

Add a peer dependency entry.

Install without saving

Install a package without editing package.json.

bashANYnpminstallno-save
bash
npm install --no-save <package>

Install a package without editing package.json.

Install globally

Install a CLI tool globally.

bashANYnpminstallglobal
bash
npm install -g <package>

Install a CLI tool globally.

Update and remove dependencies

Change package versions and clean up dependencies.

Remove a package

Remove a dependency and update manifests.

bashANYnpmuninstall
bash
npm uninstall <package>

Remove a dependency and update manifests.

Update matching packages

Update installed packages within semver ranges.

bashANYnpmupdate
bash
npm update

Update installed packages within semver ranges.

Update one package

Update one installed package.

bashANYnpmupdate
bash
npm update <package>

Update one installed package.

Deduplicate dependencies

Reduce duplicate package copies in the tree.

bashANYnpmdedupe
bash
npm dedupe

Reduce duplicate package copies in the tree.

Remove extraneous packages

Delete packages not listed in manifests.

bashANYnpmprune
bash
npm prune

Delete packages not listed in manifests.

Find duplicate packages

Report duplicate package copies in the tree.

bashANYnpmduplicates
bash
npm find-dupes

Report duplicate package copies in the tree.

Lockfiles and reproducible installs

Commands that matter for CI and predictable installs.

CI install without lifecycle scripts

Perform a clean install while skipping lifecycle scripts.

bashANYnpmcisecurity
bash
npm ci --ignore-scripts

Perform a clean install while skipping lifecycle scripts.

Refresh lockfile only

Update package-lock.json without changing node_modules.

bashANYnpmlockfile
bash
npm install --package-lock-only

Update package-lock.json without changing node_modules.

Create npm-shrinkwrap.json

Create a publishable lockfile.

bashANYnpmshrinkwraplockfile
bash
npm shrinkwrap

Create a publishable lockfile.

Install with legacy peer handling

Bypass peer dependency auto-resolution conflicts.

bashANYnpminstallpeer-deps
bash
npm install --legacy-peer-deps

Bypass peer dependency auto-resolution conflicts.

Install production deps only

Skip devDependencies during install.

bashANYnpminstallproduction
bash
npm install --omit=dev

Skip devDependencies during install.

CI install production deps only

Use lockfile while skipping devDependencies.

bashANYnpmciproduction
bash
npm ci --omit=dev

Use lockfile while skipping devDependencies.

Local development and linking

Useful local package development commands.

Pack the current package

Create a tarball from the current package.

bashANYnpmpack
bash
npm pack

Create a tarball from the current package.

Install from local tarball

Install a package from a local tarball.

bashANYnpminstalltarball
bash
npm install ./my-package-1.0.0.tgz

Install a package from a local tarball.

Recommended next

No recommendations yet.