Skip to content
Latchkey

How to Reduce npm Install Time in CI

npm install is often the first slow step in JS CI. A few changes take it from a minute-plus to a few seconds.

The wins stack: install deterministically with npm ci, cache the right directory, and skip work you do not need on CI.

Use npm ci with the built-in cache

npm ci is faster and reproducible; setup-node caches the npm cache keyed on package-lock.json.

.github/workflows/ci.yml
- uses: actions/setup-node@v4
  with:
    node-version: '20'
    cache: npm
- run: npm ci

Skip what CI does not need

Use --prefer-offline with a warm cache, and --no-audit --no-fund to skip network round-trips that add seconds for nothing.

Cache node_modules for the biggest cut

When install is still the bottleneck, cache node_modules directly keyed on the lockfile so a clean restore skips the install entirely.

Key takeaways

  • npm ci + setup-node cache is the baseline.
  • Disable audit/fund to drop needless network calls.
  • Cache node_modules to skip install on a cache hit.

Related guides

Run this faster and cheaper on Latchkey managed runners. Start free →