# npm ci

> The `npm ci` command installs dependencies exactly as specified in the lock file.

## What is the difference between npm ci and npm install?

The command that performs a clean install of dependencies strictly from `package-lock.json`, deleting existing `node_modules`. Fails if the lock file does not match `package.json`. Used in CI/CD pipelines for reproducible builds.

- Topic: npm Commands
- Type: command

## Example

Wrong:

```bash
npm install
npm run build
```

Right:

```bash
npm ci
npm run build
```

`npm ci` installs exactly what the lock file lists and fails if it is out of sync, so CI builds match local ones.

## Common mistakes

- `npm ci` fails because the lock file was not updated after editing `package.json`.

## Key points

- CI pipelines and Docker builds install with `npm ci`, not `npm install`.
- `package-lock.json` is committed and in sync with `package.json`.
- CI caches the npm cache folder, not `node_modules`, since `npm ci` deletes `node_modules` first.

## Interview questions

### Why does npm ci delete node_modules?

It always starts clean so the result depends only on the lock file, not on leftovers from earlier installs.

### Can npm ci skip devDependencies?

Yes. `npm ci --omit=dev` installs only production dependencies, which is common in Docker images.

### Does npm ci work without package-lock.json?

No. It needs `package-lock.json` or `npm-shrinkwrap.json` and stops with an error otherwise.

## Related cards

- [`npm install <package>`](https://wonderium.dev/processes/npm-install.md)
- [Lock file](https://wonderium.dev/processes/lock-file.md)
- [CI / CD](https://wonderium.dev/processes/ci-cd.md)
- [GitHub Actions](https://wonderium.dev/processes/github-actions.md)
- [npm audit](https://wonderium.dev/processes/npm-audit.md)

---

- Level: [Processes](https://wonderium.dev/processes.md)
- HTML version: https://wonderium.dev/processes/npm-ci
- Last updated: 2026-11-25
