Cache Management for Faster Installs
Beginner6 min
Optimize npm install times by understanding, managing, and leveraging the npm cache for local development and CI pipelines.
Prerequisites
- -Node.js and npm installed
Steps
1
View cache location and info
Find where npm stores its cache and check its current size.
$ npm cache ls 2>/dev/null; echo 'Cache path:' && npm config get cache && du -sh $(npm config get cache) 2>/dev/null || echo 'Cache size unavailable'
2
Verify cache integrity
Check that cached packages are not corrupted.
$ npm cache verify
This also garbage-collects unused cache entries, freeing disk space.
3
Clean the cache entirely
Remove all data from the npm cache when troubleshooting install issues.
$ npm cache clean --force
Only clean the cache when debugging install problems. Clearing it means all packages must be re-downloaded on next install.
4
Configure cache for CI
Set a custom cache directory for CI pipeline caching.
$ npm ci --cache .npm-cache
Point npm at a project-local cache directory that your CI system can persist between builds. This avoids re-downloading packages on every run.
Full Script
FAQ
Discussion
Loading comments...