Semantic version control using npm

Semantic versioning is a convention used to provide meaning to versions

If there is one great thing in the Node.js package, it is that everyone agrees to use semantic versioning for its version numbering.

The concept of semantic version control is simple: all versions have 3 digits:x.y.z.

  • The first is the major version
  • The second number is the minor version
  • The third digit is the patch version

When a new version is released, not only can you increase the number as you want, but you can also follow the following rules:

  • When you make incompatible API changes, you can upgrade to the major version
  • When you add features in a backward compatible way, you can upgrade the minor version
  • You can upgrade the patch version when making backward-compatible bug fixes

This convention is adopted in all programming languages, and one very important point is thatnpmThe software package insists on using it, because the entire system depends on it.

Why is it so important?

becausenpmSet some rules that we can use in itpackage.jsonfileChoose which version it can update our package to when we runnpm update.

The rules use these symbols:

  • ^
  • ~
  • >
  • >=
  • <
  • <=
  • =
  • -
  • ||

Let us understand these rules in detail:

  • ^: If you write^0.13.0While runningnpm updateIt can be updated to patches and minor versions:0.13.1,0.14.0and many more.
  • ~: If you write~0.13.0, While runningnpm updateIt can be updated to the patch version:0.13.1Yes, but0.14.0It's not.
  • >: You accept any version higher than the version you specify
  • >=: You accept any version equal to or higher than the version you specify
  • <=: You accept any version that is equal to or lower than the version you specify
  • <: You accept any version lower than the specified version
  • =: You accept the exact version
  • -: You accept various versions. example:2.1.0 - 2.6.2
  • ||: You group the collections together. example:< 2.1 || > 2.6

You can combine some of these symbols, such as use1.0.0 || >=1.1.0 <1.2.0Use 1.0.0 or a release version starting from 1.1.0 but lower than 1.2.0.

There are other rules:

  • Unsigned: You only accept the specific version you specify (1.2.1)
  • latest: You want to use the latest version available

Download mine for freeNode.js manual


More node tutorials: