Nepoxx Nepoxx -5 years ago 188
Node.js Question

npm install --save, what is the use of not saving

I understand the differences between

npm install something
npm install something --save
(for anyone wondering, the first one will install the dependency only while the latter will install the dependency and add it to your package.json).

However I do not understand why there is a
option in the first place. In other words, why would you ever want to install a dependency without adding it to your package.json file? Why is the --save option not default?

A lot of websites/npm modules/SaaS suggest installing their module using
npm install something
(newrelic is one of them for instance), am I missing something?

Answer Source
  1. You would have a scenario such as you need some module to install without adding dependency to package.json file, for ex. you just want to try some module, and not sure you would be really using that module in production or while deploying, so instead adding the module dependency to package.json, just give it a try without using --save. this is why npm install without --save exists.

  2. But For most of your modules you might require using --save, for ex. npm install express --save, in this case you surely know that you are going to use express for you application.

  3. The other scenario, for not using --save, would be, npm install heapdump or npm install nodemon, I would use it for testing my apps performance, but not add a dependency in the package.json :)

  4. Also, As @surajck said in comment below: when you are doing global installs, in that case adding dependencies using --save, to the package.json would not make sense.

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download