npm install downloads and installs the packages your Node.js project needs, usually from package.json, and places them in node_modules. It can also update package-lock.json and run package lifecycle scripts during installation.

What it does

  • Installs all listed dependencies when run with no package name.
  • Installs a specific package when you add a name, like npm install express.
  • Can install packages globally with -g, which makes them available system-wide instead of only in one project.
  • Uses package-lock.json to help keep versions consistent across installs.

Simple example

If a project has React, lodash, and other libraries listed in package.json, running npm install fetches those libraries and sets up the project so the code can run locally.

Why people use it

It saves you from downloading and wiring up dependencies by hand, and it helps teams stay in sync on the same package versions.

TL;DR: npm install sets up your project’s dependencies, either all at once from package.json or one package at a time.