18

Guys I know that using npm install -g we can install the node modules/packages globally, but I am not sure about the options --save and --save-dev

I have Googled it but still not clear about it. Please share your thoughts.

Kaspar Lee
  • 5,446
  • 4
  • 31
  • 54
Vinay Singh
  • 203
  • 3
  • 8
  • You might find some information here: [What is the --save option for npm install?](http://stackoverflow.com/questions/19578796/what-is-the-save-option-for-npm-install) – il_raffa Oct 10 '15 at 15:14

3 Answers3

29

--save adds the third-party package to the package's dependencies. It will be installed together with the package whenever someone runs npm install yourPackage.

--save-dev adds the third-party package to the package's development dependencies. It won't be installed when someone installs your package. It's typically only installed if someone clones your source repository and runs npm install in it.

Dev dependencies, as the same suggests, are those dependencies that are only needed for developing the package. That can include test runners, compilers, packagers, etc.

Both types of dependencies are stored in the package's package.json file. --save adds to dependencies, --save-dev adds to devDependencies. From the documentation:

devDependencies

If someone is planning on downloading and using your module in their program, then they probably don't want or need to download and build the external test or documentation framework that you use.

In this case, it's best to map these additional items in a devDependencies object.

These things will be installed when doing npm link or npm install from the root of a package, and can be managed like any other npm configuration param. See npm-config(7) for more on the topic.

For build steps that are not platform-specific, such as compiling CoffeeScript or other languages to JavaScript, use the prepublish script to do this, and make the required package a devDependency.

Edit: As of npm 5.0.0 the installed modules are added as a dependency by default, so the --save option is no longer needed.

Community
  • 1
  • 1
Felix Kling
  • 795,719
  • 175
  • 1,089
  • 1,143
7
  • --save-dev is used to save the package for development purpose. Example: unit tests, minification.
  • --save is used to save the package required for the application to run.
kattybilly
  • 117
  • 1
  • 8
0
  1. --save-dev will save npm modules in development dependencies in package.json i.e it will save inside devDependencies object.
  2. --save will save npm modules dependencies in package.json i.e it will save inside dependencies object.
Vivek Anand
  • 1,264
  • 8
  • 15