What do -save flags do with npm installation

I see package installation instructions using

npm install <package_name> 

or

 npm install <package_name> --save 

or

 npm install <package_name> --save-dev 

What is the difference between these options?

+56
npm npm-install
source share
3 answers

npm install <package_name> --save installs the package and updates the dependencies in your package.json. Since this question was asked, there were changes in npm, so --save became the default option, so you do not need to use --save to update dependencies.

npm install <package_name> --no_save installs the package, but does not update the dependencies listed in your package.json.

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

You can read more at https://docs.npmjs.com/getting-started/using-a-package.json .

+31
source share

npm install accepts 3 exclusive, optional flags that save or update the package version in your main package. json:

-S, --save: the package will appear in your dependencies.

-D, --save-dev: the package will appear in your devDependencies.

-O, --save-optional: The package will appear in your advanced options.

When using any of the above options to save dependencies with your .json package, there is an additional optional flag:

-E, --save-exact: saved dependencies will be configured with the exact version, and not with the default nver operator. Also, if you have npm-shrinkwrap.json, it will also be updated.

<scope> is optional. The package will be downloaded from the registry associated with the specified area. If the registry is not associated with this area, it is assumed that the default registry is used. See Npm-scope.

Note. If you do not specify an @ -symbol in your realm name, npm will interpret this as a GitHub repository, see below. Area names must also be followed by a slash.

Examples:

npm install sax --save npm install githubname / reponame npm install @ myorg / privatepackage npm install node -tap --save-dev npm install dtrace-provider --save-optional npm install readable-stream --save --save-exact

Note. If there is a file or folder with the name <name> in the current working directory, then he will try to install it and try to get the package by name if it is not valid.

(from white papers) https://docs.npmjs.com/cli/install

+41
source share

The --save flag no longer serves the purpose.

Earlier, as noted in other answers, the --save flag updated dependencies in the package.json project file, but npm install now includes this feature by default.

At this point, if you want to prevent npm install saving dependencies, you should use the --no-save flag.

Thanks to Coruscate5 for mentioning this in a comment .

See the npm installation documentation for details:

npm install saves all the packages specified by default. In addition, you can control where and how they are saved using some additional flags:

-P, --save -P rod: The package will appear in your dependencies. This is the default value if not -D or -O.

-D, --save -D ev: The package will appear in your devDependencies.

-O, --save -O ptional: The package will appear in your optional dependencies.

--no-save: Prevents saving to dependencies.

When using any of the above options to save dependencies, there are two additional optional flags in your package.json:

-E, --save -E xact: Saved dependencies will be configured with the exact version, and not using the default range operator for npms.

-B, --save -B undle: Saved dependencies will also be added to the bundleDependencies list.

+15
source share

All Articles