What is Semantic Versioning of NPM Packages?

Taha El Bouffi
2 min readJan 23, 2021

To prove that our public NodeJS module is healthy, reliable, and secure, we must associate to it a version. And each time we make an update to that package we should also update this version.

This version update is done following a standard universal agreement called Semantic Versioning known also as SemVer. This standard is helpful for other developers who depend on our package to figure out if they need to make a change on their own code or not.

Semantic Versioning is implemented on the package.json file and it’s represented like this:

Semantic Versioning
{
"name": "package-name",
"version": "2.13.4"
}

Patch: when we perform a bug fix to our node package module, then we should increment this part of our semantic version.

Minor: if we introduce some new features, but our package compatibility is intact, this means that we have only minor changes that implies changing the middle part of our semantic version.

Major: when the update of our package consists of developing features that won’t be compatible anymore with old versions, then we should change the major version part of the semantic version. This means that we don’t guarantee that any program that depends on our package will work as before.

Define a specific version of a dependency

If our package depends on external packages then we can specify which version of external packages we need.

"dependencies": {
"my_exact_dependence": "1.0.0",
"grater_than_dependence": ">2.2.0",
"compatible_dependence": "^2.1.4",
"patched_dependence": "~1.3.1",
"alpha_dependence": "2.1.5-alpha.11",
"beta_dependence": "1.1.0-beta.3"
"release_candidate_dependence": "2.1.5-rc.1"
},

The version of our dependence can have multiple syntax depending on our need:

  • “x.y.z”: means that we need to use this exact version of dependence. In this case “x” “y” and “z” will never change
  • “>x.y.z”: if we use the sign “>” this means that we accept versions greater than the version defined by “x.y.z”
  • “^x.y.z”: we need to add the sign “^” to specify that we will only accept minor or patch changes that are compatible with our existing code. In this case “x” is fixed and “y” or “z” may change.
  • “~x.y.z”: “~” is used to specify that we only accept patch changes, which means minor level changes. In this case “x” and “y” are fixed and only “z” can change.
  • “x.y.z-suffix.w”: we can also have in our version this syntax “-suffix.w”, where the suffix can be “alpha”, “beta” or “rc” (release candidate), and we can associate to this suffix a version “w”. This kind of semantic versioning is used for defining PRE-Release Versions.

source: https://docs.npmjs.com/about-semantic-versioning

--

--

Taha El Bouffi

Full Stack JavaScript Developer Experienced in NodeJS, Express, MongoDB, React, etc.