Course contentsShow
← JavaScript
Lesson 2494 of 2,72351. Package ManagementFree lesson

npm ci for Reproducible Installs

Using npm ci in CI/CD pipelines for clean, lockfile-based installations.

npm ci for Reproducible Installs

You'll learn why npm ci is the gold standard for consistent, reliable installs in CI/CD pipelines.

What Is npm ci?

While npm install is flexible and convenient for local development, npm ci (short for "clean install") is designed for automated environments where reproducibility matters more than convenience. It's stricter, faster, and guarantees that every installation produces exactly the same node_modules tree.

Think of npm install as a chef improvising with available ingredients, while npm ci follows the recipe to the letter every single time—no substitutions allowed.

How npm ci Differs

When you run npm ci:

  1. Deletes node_modules entirely before installing (always starts fresh)
  2. Requires package-lock.json to exist (fails without it)
  3. Never modifies package-lock.json (read-only operation)
  4. Installs exact versions from the lockfile, no resolution attempts
  5. Fails fast if there's any mismatch between package.json and package-lock.json

This strictness prevents the "works on my machine" problem. Your CI server, your teammate's laptop, and production will all have identical dependencies.

When to Use npm ci

Use npm ci in:

  • CI/CD pipelines (GitHub Actions, Jenkins, etc.)
  • Docker image builds
  • Deployment scripts
  • Any automated environment requiring consistency

Use npm install for:

  • Local development
  • Adding/updating packages
  • Interactive workflows

Key Takeaway: npm ci sacrifices flexibility for reproducibility—use it in automated builds to guarantee every environment installs the exact same dependency tree from your lockfile.