Skip to content

Knowledgebase

Deploying repeatable Node dependencies with npm ci

development

A reviewed lock file lets deployment install the dependency tree selected for the application. npm ci is useful for a clean build because it does not silently rewrite an inconsistent lock file.

Check access and requirements

Use the project’s package manager and supported Node/npm versions. Confirm the lock file belongs to the same package metadata and that private package credentials are available only where needed.

01 Deploy repeatable Node dependencies with npm ci

  1. Commit the reviewed package-lock.json or supported npm shrinkwrap file with package.json. Keep meaningful project-level installation settings consistent.

  2. Run npm ci in a clean build directory. It removes an existing node_modules directory, so do not run it casually inside an active release serving traffic.

  3. Install build-time development dependencies when the build needs them. Run the application’s declared build script and retain its output.

  4. Prepare the runtime dependency set according to the project deployment model. Omitting development dependencies before compilation can break a build that needs TypeScript or other tools.

  5. Deploy the tested output, runtime dependencies and lock metadata as one release. Keep registry tokens out of the final public artifact.

02 Example: build Node dependencies in a disposable release directory

In a clean build directory for the reviewed commit, install the locked dependency tree and compile the application using its declared script. These commands belong in the build workflow, not in an active directory currently serving customer requests.

Command example
npm ci
npm run build
git diff --exit-code -- package.json package-lock.json

Stop if installation or compilation fails. npm ci removes an existing node_modules directory and requires compatible package metadata and lock data. Keep build dependencies available until compilation is complete, then prepare the project’s intended runtime package. The final read-only Git comparison reveals unintended dependency-file changes.

Expected result: The release builds with its reviewed versions and leaves the tracked dependency files unchanged. A clean startup from the packaged output confirms that required runtime modules and copied assets were included, without borrowing an untracked dependency from an earlier deployment.

Confirm the expected result

Confirm the build completes without modifying dependency metadata and that the production startup command finds every required runtime package.

Resolve setup problems

A lock mismatch should be fixed in development and reviewed. Replacing npm ci with a broad install on production can introduce an untested dependency change.

A common question

Is npm ci the same as updating packages?

No. It installs from the existing lock. Dependency updates belong in a separate reviewed change that refreshes the lock and tests compatibility before deployment.

Sources and further reading

Was this answer helpful?

Need a little more help?

Our support team can help you find the next step.

Contact support