I saw some tutorial where the command was:
npm install --save
What does the --save
option mean?
Not able to find the a
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.
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.
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.
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
Source:https://blog.pusher.com/what-you-need-know-npm-5/
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?