npm install on your continuous integration (CI) builds take longer than you’d like? The good news is that you might be able to speed it up. Here’s what you need to know:
- Your project must have a
package-lock.jsonfile for the following command to work.
- Instead of using
npm installin your build configuration, use
npm ci("clean install") – this command runs faster than
npm installand is designed for use in CI environments. Read the npm documentation to learn more.
- Cache the npm cache files – these are typically stored in the
- You should generally avoid caching the
node_modulesdirectory in your CI builds as it can break between Node.js versions (and
npm ciautomatically removes this directory before installing anything).
Most CI services have support for caching files between builds. If you’re using GitHub Actions they have an example for caching npm cache files, and CircleCI has built in configuration features for caching.