Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What is the difference between --save and --save-dev?

What is the difference between:

npm install [package_name] 

and:

npm install [package_name] --save 

and:

npm install [package_name] --save-dev 

What does this mean? And what is really the effect of --save and -dev keywords?

like image 544
nfort Avatar asked Apr 06 '14 07:04

nfort


People also ask

What is Save dev option?

The --save-dev option will save the package under devDependencies which is useful when installing only development packages that you may not want to ship in production.

What does save dev flag do?

npm install <package_name> ---save-dev updates the devDependencies in your package. These are only used for local testing and development.


2 Answers

  • --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.
like image 45
Tuong Le Avatar answered Oct 13 '22 21:10

Tuong Le


The difference between --save and --save-dev may not be immediately noticeable if you have tried them both on your own projects. So here are a few examples...

Let's say you were building an app that used the moment package to parse and display dates. Your app is a scheduler so it really needs this package to run, as in: cannot run without it. In this case you would use

npm install moment --save 

This would create a new value in your package.json

"dependencies": {    ...    "moment": "^2.17.1" } 

When you are developing, it really helps to use tools such as test suites and may need jasmine-core and karma. In this case you would use

npm install jasmine-core --save-dev npm install karma --save-dev 

This would also create a new value in your package.json

"devDependencies": {     ...     "jasmine-core": "^2.5.2",     "karma": "^1.4.1", } 

You do not need the test suite to run the app in its normal state, so it is a --save-dev type dependency, nothing more. You can see how if you do not understand what is really happening, it is a bit hard to imagine.

Taken directly from NPM docs docs#dependencies

Dependencies

Dependencies are specified in a simple object that maps a package name to a version range. The version range is a string that has one or more space-separated descriptors. Dependencies can also be identified with a tarball or git URL.

Please do not put test harnesses or transpilers in your dependencies object. See devDependencies, below.

Even in the docs, it asks you to use --save-dev for modules such as test harnesses.

like image 79
Michael Bruce Avatar answered Oct 13 '22 21:10

Michael Bruce