install

npm install

Installs a package (and its dependencies), adding it to package.json and refreshing package-lock.json. Without arguments, installs everything already declared in the current project's package.json.

npm install [<@scope>/]<pkg>[@<version>] [--save-dev|--save-optional|--global|--force|--legacy-peer-deps]

Common flags

Flag Purpose
--save-prod (-P) Save to dependencies (default since npm 5)
--save-dev (-D) Save to devDependencies (build tools, linters, tests, typings)
--save-optional (-O) Save to optionalDependencies
--save-exact (-E) Pin exact version instead of a ^ range
--global (-g) Install into the global prefix instead of local node_modules
--force (-f) Force fetch, overwrite cache, bypass conflicts
--legacy-peer-deps Ignore npm 7+ peerDependencies conflict checks
--no-save Install without touching package.json

Examples

npm install

Install all deps declared in package.json

npm install react react-dom

Install packages and save to dependencies

npm install -D typescript eslint vitest

Add tooling to devDependencies

npm install --legacy-peer-deps

Bypass strict peer dependency conflicts

Gotcha

Since npm 5, --save is the default — package.json is always updated unless you pass --no-save. For reproducible installs in CI or Docker use `npm ci` instead: it respects the lockfile strictly and is faster.

Related commands

← All npm commands · npm vs pnpm vs Yarn · Fix Node OOM