LinuxCommandLibrary

npm-ci

Install dependencies for CI (clean install)

TLDR

Install project dependencies from package-lock.json or npm-shrinkwrap.json

$ npm ci
copy

Install project dependencies but skip the specified dependency type
$ npm ci --omit [dev|optional|peer]
copy

Install project dependencies without running any pre-/post-scripts defined in package.json
$ npm ci --ignore-scripts
copy

SYNOPSIS

npm ci

DESCRIPTION

npm-ci is a command specifically designed for use in Continuous Integration (CI) environments. Its primary purpose is to install dependencies for a Node.js project in a clean and reliable manner, optimized for speed and reproducibility. Unlike npm install, npm-ci expects a `package-lock.json` or `npm-shrinkwrap.json` file to be present. If either of these lockfiles are missing or out of sync with the `package.json` file, npm-ci will exit with an error, preventing unexpected dependency updates in your CI pipeline. This ensures that the build environment is consistent across different runs, reducing the risk of introducing bugs due to dependency mismatches. Using npm-ci is recommended when you want a reliable and error-checked way to install dependencies in an automated environment. Its goal is to provide confidence that what you are running in production is exactly what you tested in CI. It avoids automatically updating packages to newer versions, thus, if you need to update packages, you should run `npm install` instead.
Note: npm-ci requires npm version 5.7.0 or later.

CAVEATS

Requires a `package-lock.json` or `npm-shrinkwrap.json` file to be present and up-to-date with `package.json`. It also deletes your `node_modules` folder before installing dependencies to ensure a clean install.

WHEN TO USE

Use npm-ci primarily within your Continuous Integration/Continuous Deployment (CI/CD) pipelines. It ensures a consistent and predictable build environment.
For development, use `npm install` to manage dependencies.

ERROR HANDLING

npm-ci will exit with a non-zero exit code if any errors occur during dependency installation or if the lockfile is missing or out-of-date. This allows CI systems to automatically fail builds that encounter dependency issues.

HISTORY

Introduced in npm version 5.7.0 as a dedicated command for CI environments, addressing the need for faster and more reliable dependency installation compared to a standard `npm install`.

SEE ALSO

npm install(1), npm update(1), npm shrinkwrap(1), npm package-lock.json(5)

Copied to clipboard