Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Difference between npm install --save and npm install --save-dev

Tags:

javascript

npm

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.

like image 291
Vinay Singh Avatar asked Oct 10 '15 14:10

Vinay Singh


People also ask

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

What does --save and --save-dev do? Well, You already know the answer now, don't you? --save saves the name and version of the package being installed in the dependency object. --save-dev saves the name and version of the package being installed in the dev-dependency object.

What does npm Install -- Save dev mean?

npm install [package-name] –save-dev: When –save-dev is used with npm install, it signifies that the package is a development dependency. A development dependency is any package that absence will not affect the work of the application.

What is difference between npm install?

npm install (in Short: npm i)npm install , or npm i , is used to install dependencies: It will install all the dependencies. If you use ^ or ~ when you specify the version of your dependency, npm may not install the exact version you specified. npm install can update your package-lock.

Why do we not use -- save with npm install anymore?

You don't need --save anymore for NPM installs. This was long the golden standard to install a package and save it as a dependency in your project. Meaning if we didn't specify the --save flag, it would only get locally installed and not added to the package.


2 Answers

--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.

like image 153
Felix Kling Avatar answered Oct 28 '22 19:10

Felix Kling


  • --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 44
kattybilly Avatar answered Oct 28 '22 18:10

kattybilly