npm ci is a command used in Node.js to install project dependencies listed in the package-lock.json file. It stands for “clean install” and is designed to install dependencies in a more consistent and reliable manner compared to npm install. Here are the key differences and benefits:
-
Consistency:
npm ciinstalls exactly what is in yourpackage-lock.json, ensuring that the exact same versions of dependencies are installed every time. This makes builds more predictable and reproducible. -
Speed: It can be faster than
npm installbecause it skips several steps thatnpm installperforms, such as updating thepackage-lock.jsonfile and performing dependency resolution. -
Clean Slate: It removes the
node_modulesdirectory before installing, ensuring that there are no leftover dependencies from previous installations that could cause issues.
How to use npm ci
- Ensure you have a
package-lock.jsonfile in your project. - Run the command in your project directory:
npm ci
This will clean your node_modules directory and install dependencies as specified in the package-lock.json file.
Typical Use Cases
- CI/CD Pipelines: It is commonly used in Continuous Integration/Continuous Deployment pipelines to ensure a clean and consistent environment for each build.
- Reproducible Environments: When you need to ensure that your development, staging, and production environments all use the exact same dependencies.
Example
Assuming you have a project with a package-lock.json file, running npm ci would look like this:
npm ci
This will quickly install all the dependencies specified in the package-lock.json file after removing the node_modules directory.

Leave a Reply