What is the difference between the --save-dev and --save when installing a package via npm ?

4 answers 4

-S, --save: The package will be displayed in your dependencies

-D, --save-dev: the package will be displayed in your devDependencies

See npm-install for more details.

    If you specify the --save flag when installing the package, its name and version will be written in the package.json file in the dependencies section.

    enter image description here

    If you install with the --save-dev flag, then the name and version will fall into the devDependencies section

    enter image description here

      In the npm 6.5 version, you can not write -save or -s , npm itself will add the installed package to you in "dependencies": {}.

      From the documentation https://docs.npmjs.com/cli/install :

      -P , --save-prod : again, save to "dependencies": {}. This is your production code, it will be included in your final product. Add here only those libraries that will be used when running your final product (web page for example).

      -D , --save-dev : save the package to "devDependencies": {}. These are the packages that you use in the development process, LESS, SASS preprocessors, code validators, JShint Slint, JS: Babel preprocessors. These packages will not be included in the final product.

      -O , --save-optional : the package will be added to "optionalDependencies": {}. these packages can be used in work, but if they are unavailable or an error occurs during their installation, then npm will just skip them and continue working.

      --no-save : --no-save package from being saved in package.json.

      + Additional flags:

      -E , --save-exact : save the version of the package exactly as indicated.

      -B , --save-bundle : save the package to "bundleDependencies": {}.

        If I remember correctly, then when you add -dev , then in addition to the package everything that it depends on is put.

        For example:

         bower install jqueryvalidation --save-dev 

        Will put jqueryvalidation and jquery. because how dependent on her. if you specify without -dev, jquery will not be supplied.

        • No, it is not. See the answer @ stas0k - xEdelweiss