Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What is the purpose of using --save-exact

Tags:

Want to know the use of -exact with --save

npm i [email protected] --save-dev --save-exact
like image 932
Munawar Khan Avatar asked Oct 31 '19 07:10

Munawar Khan


People also ask

What is the purpose of npm I -- save?

The --save option instructed NPM to include the package inside of the dependencies section of your package. json automatically, thus saving you an additional step.

Why do we need .npmrc file?

The npmrc manages the npm config files. The config setting for npm is gotten from the command line, environment variables and the npmrc files. You can use the npm config command to update and edit the contents of the user and global npmrc files.

What purpose does the -- save Dev flag serve?

@Kokodoko When you use the --save-dev flag, the package is added to your devDependencies object. If/when someone installs your package, all the dependencies are downloaded but the devDependencies are not, since they aren't required at runtime. As the answer stated, this saves them time and space.

Why do we not use -- save with npm install anymore?

You don't need --save anymore for NPM installs. This was long the golden standard to install a package and save it as a dependency in your project. Meaning if we didn't specify the --save flag, it would only get locally installed and not added to the package.


2 Answers

For example, I use --save-exact when I manage projects with webpack. As you know, when you install a package like npm install --save-dev webpack for example, our package.json will add something like:

"devDependencies": {
    "webpack": "^5.1.3",
}

What does it mean?

When you delete your node_modules folder (for example when you put your files on github)and you make a npm install, maybe a version of any package could be updated and if the version is not a major version (X.0.0), Maybe your application stops working because of update. For example from 5.1.3 maybe the package is going to uptade to 5.1.8
So, the --save-exact will generate the next package.json code

"devDependencies": {
    "webpack": "5.1.3",
}

Whitout the ^, the version of the package of webpack in this case will be always the same 5.1.3.

More reference here about semantic version with NPM:

  • About semantic versioning

PDT: Sorry for my poor English.

like image 192
JORGE GARNICA Avatar answered Sep 24 '22 05:09

JORGE GARNICA


When using save=true, npm install will automatically add the package into package.json without the need of using npm install --save every time you run the command. save-exact=true will make sure that no sliding versions (with ~ or ^ ) will not be installed.

reference for more information click here

or please go through this https://docs.npmjs.com/cli/install

like image 39
Pardeep Avatar answered Sep 26 '22 05:09

Pardeep