Categories
Node.js Quick Tips Quick Tips

How to speed up npm install in your Node.js builds

< 1 min read

Does the 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.json file for the following command to work.
  • Instead of using npm install in your build configuration, use npm ci ("clean install") – this command runs faster than npm install and 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 ~/.npm directory.
  • You should generally avoid caching the node_modules directory in your CI builds as it can break between Node.js versions (and npm ci automatically 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.

Leave a Reply

Your email address will not be published. Required fields are marked *