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

Asked

Viewed 482 times

6

In Node.js environment when we fetch modules from NPM suffixes can be used to specify versions.

For example, in the package.json I often see:

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

What are these suffixes ^, ~, and how to use?

1 answer

6


Here is a list for those who need it, and based on the assumption that the versions indicated comply with the versioning standard SEMVER*:

I’ll use 1.2.3 only as example version

  • ~1.2.3 "rough version". Will keep the version minor, or only allows changes in the last versioning parameter. That is: 1.2 and >=3 in the last parameter.
  • ^1.2.3 "compatible with" Will accept change of smaller versions, but does not allow new versions (first parameter). Ie: 1 and >=2.>=3 in the last parameters.
  • 1.2.3 Exact version.
  • >1.2.3 Greater than...
  • >=1.2.3 Greater or equal...
  • <1.2.3 Less than...
  • <=1.2.3 Smaller or equal...
  • 1.2.x 1.2.0, 1.2.1, etc., but not 1.3.0. (almost similar to ~1.2.3)
  • http://url.com/tarball 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 Github would be something like: https://github.com/contaGithub/nomeProjeto/tarball/master
  • * wildcard, accepts any version.

* - SEMVER is a versioning model, to make it easier to predict whether the changes between versions of a software are large, small or just fixes. The SEMVER model consists of three numerical parts which are/represent respectively changes to the software of character: maior, menor, correção.

Browser other questions tagged

You are not signed in. Login or sign up in order to post.