What are the suffixes of NPM versions and what do they do?

6

In Node.js environment when we are going to get modules from NPM you can use suffixes to specify versions .

For example, in package.json I see many times:

"dependencies": {
    "async": "~1.4.2",
    "express": "^4.13.3",

What are these suffixes ^ , ~ , and how are they used?

    
asked by anonymous 05.09.2015 / 22:39

1 answer

6

Here is a list for those who need it, and assuming that the versions refer to the versioning rule SEMVER * :

I will use% w / o only as version example

  • 1.2.3 "approximate version". It will keep the minor version, or it only allows changes in the last versioning parameter. That is: ~1.2.3 and 1.2 in the last parameter.
  • % com_config "Compatible with" Will accept change from smaller versions, but does not allow new versions (first parameter). That is: >=3 and ^1.2.3 in the last parameters.
  • 1 Exact version.
  • >=2.>=3 Greater than ...
  • 1.2.3 Greater than or equal ...
  • >1.2.3 Less than ...
  • >=1.2.3 Less than or equal ...
  • <1.2.3 1.2.0, 1.2.1, etc., but not 1.3.0. (almost similar to <=1.2.3 )
  • 1.2.x By passing a url it is possible to install a tarball , for example Github for cases where the package / software is not published in NPM. For example in Github it would be something like: ~1.2.3
  • http://url.com/tarball wildcard , accepts any version.
  

* - SEMVER is a versioning template , to make it easier to predict whether changes between software versions are large, small or just fixes. The SEMVER model consists of three parts, which are / respectively represent changes to the character software: https://github.com/contaGithub/nomeProjeto/tarball/master , * , maior .

    
05.09.2015 / 22:39