Why wouldn't you want to use the `--save` option for npm install?

With package managers like Bower or npm, I think --save is not automatic for the following reasons:

  1. Not all dependencies are production dependencies (see --save-dev).
  2. Sometimes you need to test a package without altering your package.json.
  3. You may prefer to install locally some packages that your colleagues installed globally on their computer.

Packages installed without --save are not considered as dependencies and are kept separate. You can detect them easily as extraneous packages with npm ls and remove them instantly with npm prune.

Now if you think extraneous packages are a bad thing, you can of course use --save everytime you install a new package. For practical reasons, be aware that you can use the -S shortcut instead of --save. Moreover, if you often forget to use the option, you could define an alias in your shell.

Finally, if you use Yarn, notice that the yarn add command will add each package as a dependency. No --save flag anymore.


To quote one of the npm maintainers:

In the last couple years, quite a bit has changed here, which renders parts of this issue moot: [...] It’s [...] easy enough to run npm config set save true as an end users. That said, there are still a number of rough spots when making --save the default:

  • While the cognitive load of having to remember --save or --save-dev at install time is an irritating niggle, it does force you to choose at install time whether a package is a dependency or devDependency.
  • Moving packages between sections in package.json is still a little more difficult than it should be, which makes cleaning up after things when you forget to specify that somethi[ng] is a devDependency. [...] I don’t think it’s in the best interests, as a result, to opt everyone into saving everything by default.

(from https://github.com/npm/npm/issues/5108)