What is the --save option for npm install?

前端 未结 12 719
野性不改
野性不改 2020-11-22 13:54

I saw some tutorial where the command was:

npm install --save

What does the --save option mean?

Not able to find the a

相关标签:
12条回答
  • 2020-11-22 13:55

    npm install --save or npm install --save-dev why we choose 1 options between this two while installing package in our project.

    things is clear from the above answers that npm install --save will add entry in the dependency field in pacakage.json file and other one in dev-dependency.

    So question arises why we need entry of our installing module in pacakge.json file because whenever we check-in code in git or giving our code to some one we always give it or check it without node-modules because it is very large in size and also available at common place so to avoid this we do that.

    so then how other person will get all the modules that is specifically or needed for that project so answers is from the package.json file that have the entry of all the required packages for running or developing that project.

    so after getting the code we simply need to run the npm install command it will read the package.json file and install the necessary required packages.

    0 讨论(0)
  • 2020-11-22 14:02

    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:

    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.

    0 讨论(0)
  • 2020-11-22 14:02

    npm install package_x --save

    The given package (package_x) will be saved in package.json inside dependencies. if you add

    npm install <<package_x>> --save-dev

    then it will be saved inside devDependencies.

    0 讨论(0)
  • 2020-11-22 14:04

    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.

    0 讨论(0)
  • 2020-11-22 14:05

    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
    

    Source:https://blog.pusher.com/what-you-need-know-npm-5/

    0 讨论(0)
  • 2020-11-22 14:08

    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?

    0 讨论(0)
提交回复
热议问题