Interview Q&A / Node.js

BeginnerQuick answer1 min readUpdated 3 Oct 2026

What is the difference between npm install and npm ci?

SHORT ANSWER

npm install can update the lock file and resolves versions from package.json. npm ci deletes node_modules and installs exactly what package-lock.json says, failing if the two disagree, which makes builds repeatable.

Explain it simply

npm install is like cooking from a recipe with notes such as "some tomatoes". npm ci is like cooking from a printed bill of exact quantities. The first is flexible and good on your laptop. The second gives the same result every time, which is what a build server wants.

Example

bash
# daily development: add or update packages
npm install axios

# CI pipeline or Docker build: clean, exact, fast
npm ci

# production image, skip devDependencies
npm ci --omit=dev

What npm ci does differently:

  • Removes any existing node_modules first.
  • Never writes to package.json or package-lock.json.
  • Exits with an error if the lock file and package.json do not match, or if there is no lock file.
  • Installs only what the lock file lists, so it is often faster.

If the pipeline fails with "package.json and package-lock.json are not in sync", someone changed a dependency without committing the updated lock file.

What to say in the interview

"I use npm install while developing, and npm ci in CI and Docker because it installs exactly from the lock file, wipes node_modules, and fails on mismatch, so builds are reproducible."

Common mistakes

  • Running npm install in a pipeline and getting different versions from the developer's machine.
  • Not committing package-lock.json.

#npm#ci-cd#package-lock

Related questions

Practise more Node.js questions

Test your recall with short answers, then return to the detailed explanations when you need context.

Open Node.js quick answers →

Get new questions like this by email

One short email when something new and useful lands. No spam, unsubscribe in one tap.

By subscribing you agree to the Privacy Policy.