What is the difference between npm install and npm ci?
BeginnerConceptNode.js builds (npm, package.json)
Answer
Short answer
npm install installs packages based on package.json and may update package-lock.json. npm ci ("clean install") deletes node_modules and installs exactly what's in the lockfile — and fails if the lockfile and package.json don't match. Use npm install on your laptop to add/update packages; use npm ci in CI and Docker builds.
Comparison
npm install |
npm ci |
|
|---|---|---|
| Source of truth | package.json (+ lockfile) | lockfile only |
| Changes the lockfile? | Can | Never |
| Existing node_modules | Updated in place | Deleted first |
| Out-of-sync lockfile | Silently fixes it | Fails the build |
| Repeatable? | Not guaranteed | Yes |
Example
npm install axios # developer adds a package → package.json + lockfile updated, committed
npm ci # pipeline installs the exact same tree
npm ci --omit=dev # production image: skip devDependencies
What to say in the interview
"npm ci gives deterministic installs from package-lock.json and fails if it's out of sync, so it's what we use in pipelines and Dockerfiles. npm install is for developers changing dependencies."
More on Node.js builds (npm, package.json)
What is package.json and what does it contain?BeginnerHow do you build and run a Node.js application?BeginnerWhy must package-lock.json be committed to Git?BeginnerWhat is the difference between dependencies and devDependencies?BeginnerWhat do the ^ and ~ symbols mean in package.json versions?BeginnerWhat are npm scripts and how do you run them?Beginner