npm ci is a command that stands for "clean install" and is similar to npm install, but it is meant to be used in automated environments such as test platforms, continuous integration, and deployment. The main differences between npm install and npm ci are:
- The project must have an existing
package-lock.jsonornpm-shrinkwrap.json. - If dependencies in the package lock do not match those in
package.json,npm ciwill exit with an error, instead of updating the package lock. npm cican only install entire projects at a time: individual dependencies cannot be added with this command.- If a
node_modulesfolder is already present, it will be automatically removed beforenpm cibegins its install. - It will never write to
package.jsonor any of the package-locks: installs are essentially frozen.
npm ci is always faster than npm install because it skips some features and always installs packages from the package-lock.json file, which means it doesnt need to check the node_modules cache. This makes it a great choice for CI/CD pipelines and Docker builds. It also ensures that all developers working on a project have the same exact dependencies and versions installed, which helps to eliminate inconsistencies in the development environment, making it easier to reproduce and debug issues. To use npm ci, simply run the following command in your project directory: npm ci .

