1

If I'm using a unix system and want to clear out my node modules folder, is there any difference or advantage to running

rm -rf node_modules

then npm i

versus

npm ci

As I understand it they're producing the same result, but is what's going on under the hood the same?

RobC
  • 22,977
  • 20
  • 73
  • 80
Reikon
  • 43
  • 1
  • 8
  • 1
    https://stackoverflow.com/questions/52499617/what-is-the-difference-between-npm-install-and-npm-ci – Nsevens Mar 01 '21 at 10:45
  • ^ this is not what I asked - I'm talking about running rm -rf node_modules before running npm i and if that's the same as npm ci – Reikon Mar 01 '21 at 11:05

1 Answers1

0

Running npm help ci will give you the answer; in short it removes the node_modules as well but it's meant for the CI so some additional tasks are performed:

This command is similar to npm install, except it's meant to be used in automated environments such as test platforms, continuous integration, and deployment or any situation where you want to make sure you're doing a clean install of your dependencies. It can be significantly faster than a regular npm install by skipping certain user-oriented features. It is also more strict than a regular install, which can help catch errors or inconsistencies caused by the incrementally-installed local environments of most npm users.

In short, the main differences between using npm install and npm ci are:

  • The project must have an existing package-lock.json or npm-shrinkwrap.json.
  • If dependencies in the package lock do not match those in package.json, npm ci will exit with an error, instead of updating the package lock.
  • npm ci can only install entire projects at a time: individual dependencies cannot be added with this command.
  • If a node_modules is already present, it will be automatically removed before npm ci begins its install.
  • It will never write to package.json or any of the package-locks: installs are essentially frozen.