Speed up your Node CI Pipelines
Today we’re going to talk about a small improvement that can make our node pipelines much faster.
A few days ago I came across an npm command I had never read or heard of. Until then, I used npm install to prepare the environment with all dependencies in my continuous integration piplines. But after I had dealt with it a little bit and test it out, I was impressed. The pipelines were more than 30% faster.
The command I am talking about is, as you can read in the headline, npm ci. But what does it actually do? Why is it so much faster? And what are the differences to npm install? Below you can see a list of the most important differences between npm install and npm ci.
- npm ci ignores the specified dependencies in package.json and only installs the dependencies from the package-lock.json file.
- If package.json and package-lock.json do not contain the same dependencies, an error is returned. The npm install command, on the other hand, would adjust the package-lock.json file.
- If a node_modules folder already exists, through npm ci it’ll be removed and completely recreated.
- The package.json and package-lock.json are frozen. Both will not change.
Through all that I listed above and more, npm ci is much faster than npm install. I can recommend everyone to try it in their ci. Not only because of the time improvement. Also because of the fact that an error is thrown if the package.json and package-lock.json don’t contain the same dependencies.
Today we talked about npm ci and the difference to npm install. I hope the short article was helpful and you were able to take something away. If you have any questions or notes, please leave them in the comments.