Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

Tags:

node.js

npm

I understand the differences between npm install something and 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 --save 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?

Edit: Starting from NPM 5, --save is now on by default.

like image 268
Nepoxx Avatar asked Jan 07 '15 14:01

Nepoxx


People also ask

What happens if you npm install without -- save?

–no-save: When this command is used with npm install it will not allow the installed packages from being saved into the dependency section.

Why we use -- save in npm install?

--save. NPM provides the --save option while installing the packages. If we use the --save option after installing the package, it will be saved in package. json inside dependencies.

What is no save npm?

if you run: npm install --no-save express. now, if you check your node_modules folder the package is downloaded but package. json is not updated. When you try to run your code, since express is available in node_module it can be picked up by your code or any third party library that you have in your project.


1 Answers

  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.

like image 66
Naeem Shaikh Avatar answered Oct 11 '22 20:10

Naeem Shaikh