save option for npm install?

I saw some tutorial where the command was:

npm install --save

What does the --save option mean?

Not able to find the answer on Google.


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.

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 used. The other save options still exist and are listed in the documentation for npm install .


It won't do anything if you don't have a package.json file. Start by running npm init to create one. Then calls to npm install --save or npm install --save-dev or npm install --save-optional will update the package.json to list your dependencies.


To add package in dependencies:

npm install my_dep --save

or

npm install my_dep -S

To add package in devDependencies

npm install my_test_framework --save-dev

or

npm install my_test_framework -D

package.json 在这里输入图像描述

链接地址: http://www.djcxy.com/p/20062.html

上一篇: JSON和JavaScript对象有什么区别?

下一篇: 保存npm install的选项?