Search code examples
node.jsgruntjs

What is the the meaning of `>=` or `~` before (node) module version numbers?


Can anyone explain the meaning of >= or ~ before (node) module version numbers. I looked around but i can't figure it out.

How do i call these 'prefixes'? I assume >= means bigger or equal, like in many programing languages.

{
    "node": ">=0.8",
    "grunt": "~0.4.2",
}

Solution

  • npm's documentation explains these nicely. They're called "ranges", and they're used to determine a range of versions that a package should be able to depend on:

    https://docs.npmjs.com/cli/v6/using-npm/semver#ranges

    A >= range as you guessed allows any version greater than or equal to the specified version.

    A ~ range allows for upgrades while keeping within the specified major or minor version. ~1.2.3 will allow an upgrade to 1.2.9 but not to 1.3.0 for example. ~1 would allow an upgrade to 1.9.0 but not 2.0.0.


    Further reading on Semantic Versioning may also be useful. Semantic versioning is what dictates how version numbers should be incremented so as not to break dependent packages, but still allowing for upgrades and bug fixes.