npm install Explained

What npm install does, with an example.

Published November 10, 2026

npm install downloads the dependencies listed in package.json into node_modules and records exact versions in package-lock.json. With a package name it also adds that package to package.json.

How it works

Dependencies go in 'dependencies'; use --save-dev (-D) for build and test tools. -g installs globally, which is best reserved for CLIs.

npm ci installs strictly from the lockfile for reproducible builds.

Try it

npm install express
added 64 packages in 3s
npm install -D jest
added 290 packages

Practical examples

Install everything

npm install

Add a dependency

npm install lodash
npm install -D typescript

Specific version or tag

npm install react@18.3.1
npm install vite@latest

Reproducible CI install

npm ci

Common mistakes

  • Committing node_modules.
  • Forgetting -D for dev tools.
  • Using sudo with global installs.

Key takeaways

  • npm install downloads the dependencies listed in package.json into node_modules and records exact versions in package-lock.json.
  • Run npm help <command> for every option.
  • Commit package-lock.json.

FAQ

install vs ci?

install updates the lockfile if needed; ci installs exactly from it.

Does this work with yarn or pnpm?

They have equivalents with similar commands.

More JavaScript articles