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 ciSkip 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
How to Cache pip and Poetry Dependencies in CICache pip and Poetry dependencies in GitHub Actions to skip reinstalling Python packages every run. setup-pyt…
How to Warm Dependency Caches in CIPre-populate CI dependency caches from your default branch so pull-request runs always hit a warm cache inste…
How to Cache Dependencies in GitHub Actions (Every Ecosystem)Cache dependencies in GitHub Actions with actions/cache - correct keys and paths for npm, yarn, pnpm, pip, Ma…
How to Reduce Cold Starts in CICut CI cold-start time: warm dependency caches, prebuilt images, and warm-pool runners that skip the provisio…