I saw that npm ci
for installing packages in a project that I got into recently.
Up to now, I had used npm install
for installing all dependencies of a project.
But I got to know that npm ci
is much faster than npm install
. In some cases, it's even twice faster.
I'll explan
- Why npm ci is faster than npm install
- What npm ci can't do
- Why you should use npm ci instead of npm install
Why npm ci
is faster than npm install
npm ci
installs all dependencies from package-lock.json . If there is no package-lock.json or there is a dependency problem, it throws an error.
npm install
installs all dependencies from package-lock.json and if dependencies need to be updated, it does and if there is no package-lock.json, it creates package-lock.json.
What npm ci
can't do
It installs dependencies from package-lock.json
. That's it. You can't add or update packages using npm ci
.
Why you should use npm ci
instead of npm install
If you're working on a project, you may don't need to install all of the dependencies every time. But if you deploy the project, you need to install all dependencies. For that, use npm ci
. It'll be faster than npm install
.
Before deploying, you have to make sure that all dependencies in package-lock.json are updated. Otherwise, your project may not be working. And for saving time, make sure of one more thing: There is no node_modules because npm ci
removes node_modules anyways before building. That would be a waste of time.
Install-Time Differences
npm install
Time: 77.562s
npm ci
Time: 46.599s