Member-only story
npm ci vs. npm install — Which Should You Use in Your Node.js Projects?
2 min readJun 29, 2021
Let’s learn some thing new, which is very useful for you for developement.
npm install,
- It will install all the dependencies.
- If you use
^
or~
when you specify the version of your dependency, npm may not install the exact version you specified. npm install
can update yourpackage-lock.json
when there are changes such as when you install a new dependency.
npm ci,
- It will delete your
node_modules
folder to ensure a clean state. - It will look in your
package-lock.json
to install all the dependencies with the exact version. - Unlike
npm install
,npm ci
will never modify yourpackage-lock.json
. It does however expect apackage-lock.json
file in your project — if you do not have this file,npm ci
will not work and you have to usenpm install
instead. - npm ci is fast — in some cases, twice as fast as using npm i.
Which to Use?
- Use
npm install
to install new dependencies, or to update existing dependencies - Use
npm ci
when running in continuous integration, or if you want to install dependencies without modifying thepackage-lock.json
.
Summary
- npm i, can update your
package-lock.json
- npm ci , package-lock.json to install all the dependencies with the exact version.
Keep learning, Keep growing!
Let’s connect on LinkedIn!
Don’t forget to follow me on medium for more updates.