0

I see --save mentioned most of the time when installing packages. What does it mean in English? What do I lose if I don't use --save? Is it ok to just apply this option every time?

docs.npmjs.com/cli/install merely describes it as:

-S, --save: Package will appear in your dependencies

--Afternote:

I read the other question suggested as a duplicate, and I think that OP and myself were actually asking about what updating dependencies mean and not what what --save mean. It quite clear that --save means to save something, but for what purpose is the more important question. The documentation does not mention any reason. The answer given here by @nicovank helped me and I learned that it is for the purpose of duplicating the project in future, if I have not understood wrongly.

Old Geezer
  • 14,854
  • 31
  • 111
  • 198
  • 2
    Possible duplicate of [What is the --save option for npm install?](http://stackoverflow.com/questions/19578796/what-is-the-save-option-for-npm-install) – Gimby Jan 31 '17 at 15:39

1 Answers1

2

Using the save flag specifies to npm that this depedency will be saved in the package.json file, under dependencies.

You can use --save-dev to save under the devDependencies.

By using either one of those, the version saved will be for example ^1.0.0, meaning 1.0.0 or above. If you want to save the exact version you are using, use the --save-exact flag. This can be useful if you want to prevent changes in the library making your application unable to run.

Once all your dependencies are saved, you can later reinstall them all using npm install.

Is it ok to just apply this option every time?

Yes, and you should, to keep track of the dependencies of your project.

More documentation on install flags here.

nicovank
  • 3,157
  • 1
  • 21
  • 42