NPM Semantic Versioning

2 min read

Why is it important to understand the working of npm versioning?

Like every code, npm packages also need to be updated. Whether it's rolling out a new feature or fixing the bugs in the existing ones, package authors update their packages. But since almost every package itself is dependent on many other packages developed by other developers so if not versioned carefully might break the package.

You can see the versions of your favorite package either on the versions tab on the npm website or on the Github repository of the project you might find a changelog file which is a documented file of all the notable changes.

Semantic Versioning

NPM follows semantic versioning. These are a simple set of rules and requirements that dictate how version numbers are assigned and incremented.

Each version contains 3 digits separated by a dot ~ MAJOR.MINOR.PATCH

For example, suppose the current version of an npm package is 7.14.6 then:

  • 7 is the Major version
  • 14 is the Minor version
  • 6 is the Patch version

Major version is incremented when

  • The changes are not backward compatible
  • The changes are big

Minor version is incremented when

  • features are added in a backward-compatible manner

Patch version is incremented when

  • you make bug fixes that are backward compatible
  • you don't break the old code

How to increase the versions?

If the current version is 7.14.6 and if the update is a:

  • Major one, 7 is incremented to 8 while 14 and 6 are reset back to 0 i.e, 7.14.6 -> 8.0.0
  • Minor update, then 14 is incremented to 15 while 6 is reset back to 0 i.e, 7.14.6 -> 7.15.0
  • Patch update, then only the patch version is incremented i.e, 7.14.6 -> 7.14.7

Explore Further 🌌

If you found this article helpful, I would be grateful for your support.
"Buy me some paneer curry"