Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Node package.json Dependencies

Tags:

node.js

New to Nodejs and looking at the dependencies section of the package.json file. Could someone explain to me what the ~ and * symbols do when setting the versions?

like image 315
tommyd456 Avatar asked Nov 16 '25 18:11

tommyd456


1 Answers

From the documentation:

The following range styles are supported:

  • 1.2.3 A specific version. When nothing else will do. Note that build metadata is still ignored, so 1.2.3+build2012 will satisfy this range.
  • >1.2.3 Greater than a specific version.
  • <1.2.3 Less than a specific version. If there is no prerelease tag on the version range, then no prerelease version will be allowed either, even though these are technically "less than".
  • >=1.2.3 Greater than or equal to. Note that prerelease versions are NOT equal to their "normal" equivalents, so 1.2.3-beta will not satisfy this range, but 2.3.0-beta will.
  • <=1.2.3 Less than or equal to. In this case, prerelease versions ARE allowed, so 1.2.3-beta would satisfy.
  • 1.2.3 - 2.3.4 := >=1.2.3 <=2.3.4
  • ~1.2.3 := >=1.2.3-0 <1.3.0-0 "Reasonably close to 1.2.3". When using tilde operators, prerelease versions are supported as well, but a prerelease of the next significant digit will NOT be satisfactory, so 1.3.0-beta will not satisfy ~1.2.3.
  • ~1.2 := >=1.2.0-0 <1.3.0-0 "Any version starting with 1.2"
  • 1.2.x := >=1.2.0-0 <1.3.0-0"Any version starting with 1.2"
  • ~1 := >=1.0.0-0 <2.0.0-0 "Any version starting with 1"
  • 1.x := >=1.0.0-0 <2.0.0-0 "Any version starting with 1" Ranges can be joined with either a space (which implies "and") or a || (which implies "or").

Addendum:

* means any version.

like image 99
Brad Avatar answered Nov 18 '25 09:11

Brad



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!