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.
转载于:https://stackoverflow.com/questions/19578796/what-is-the-save-option-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
You can also use -S
, -D
or -P
which are equivalent of saving the package to an app dependency, a dev dependency or prod dependency. See more NPM shortcuts below:
-v: --version
-h, -?, --help, -H: --usage
-s, --silent: --loglevel silent
-q, --quiet: --loglevel warn
-d: --loglevel info
-dd, --verbose: --loglevel verbose
-ddd: --loglevel silly
-g: --global
-C: --prefix
-l: --long
-m: --message
-p, --porcelain: --parseable
-reg: --registry
-f: --force
-desc: --description
-S: --save
-P: --save-prod
-D: --save-dev
-O: --save-optional
-B: --save-bundle
-E: --save-exact
-y: --yes
-n: --yes false
ll and la commands: ls --long
This list of shortcuts can be obtained by running the following command:
$ npm help 7 config
npm install package_x --save
The given package (package_x) will be saved in package.json inside dependencies. if you add
npm install <> --save-dev
then it will be saved inside "devDependencies".
As of npm 5, it is more favorable to use --save-prod
(or -P
) than --save
but doing the same thing, as is stated in npm install. So far, --save
still works if provided.
As of npm 5, npm will now save by default. In case,if you would like npm to work in a similar old fashion (no autosave) to how it was working in previous versions, you can update the config option to enable autosave as below.
npm config set save false
To get the current setting, you can execute the following command:
npm config get save
npm i (Package name) --save
Simplily, using above command we ll not need to write package name in your package.json file it ll auto add its name and dependency with version that you ll need at time when you go for production or setup another time.
npm help install
Above command ll help find out more option and correct def.shown in pic
according to NPM Doc
So it seems that by running npm install package_name
, the package dependency should be automatically added to package.json right?
The easier (and more awesome) way to add dependencies to your package.json is to do so from the command line, flagging the npm install command with either --save or --save-dev, depending on how you'd like to use that dependency.