Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What is the --save option for npm install?

Tags:

node.js

npm

I saw some tutorial where the command was:

npm install --save 

What does the --save option mean?

like image 476
Dmitri Avatar asked Oct 24 '13 23:10

Dmitri


People also ask

Do I need to use the -- save with npm install?

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

What is -- save exact in npm?

When using save=true , npm install will automatically add the package into package. json without the need of using npm install --save every time you run the command. save-exact=true will make sure that no sliding versions (with ~ or ^ ) will not be installed.


2 Answers

Update npm 5:

As of npm 5.0.0, installed modules are added as a dependency by default, so the --save option is no longer needed. The other save options still exist and are listed in the documentation for npm install.

Original answer:

Before version 5, NPM simply installed a package under node_modules by default. When you were trying to install dependencies for your app/module, you would need to first install them, and then add them (along with the appropriate version number) to the dependencies section of your package.json.

The --save option instructed NPM to include the package inside of the dependencies section of your package.json automatically, thus saving you an additional step.

In addition, there are the complementary options --save-dev and --save-optional which save the package under devDependencies and optionalDependencies, respectively. This is useful when installing development-only packages, like grunt or your testing library.

like image 81
voithos Avatar answered Oct 12 '22 10:10

voithos


Update as of npm 5:

As of npm 5.0.0, installed modules are added as a dependency by default, so the --save option is no longer needed. The other save options still exist and are listed in the documentation for npm install.


Original Answer:

To add package in dependencies:

npm install my_dep --save 

or

npm install my_dep -S 

or

npm i my_dep -S 

To add package in devDependencies

npm install my_test_framework --save-dev 

or

npm install my_test_framework -D 

or

npm i my_test_framework -D 

package.json enter image description here

like image 41
Joe L. Avatar answered Oct 12 '22 12:10

Joe L.