Back to results for “Deployment”
Node.js › Git & Project Management

What is semantic versioning (semver), and how does it inform how a Node.js package's version number should change between releases?

Intermediate

Answer

Semantic versioning uses a MAJOR.MINOR.PATCH format, where a PATCH increment indicates a backward-compatible bug fix, a MINOR increment indicates new backward-compatible functionality, and a MAJOR increment indicates a breaking change -- consumers of a package rely on this convention (combined with caret/tilde ranges in package.json) to safely receive automatic bug-fix and feature updates without breaking their application, while being explicitly warned (and required to manually opt in) when a breaking major version change occurs.
// package.json version ranges leveraging semver conventions
"dependencies": {
  "lodash": "^4.17.0", // accepts any 4.x.x update, but not 5.0.0
  "express": "~4.18.0" // accepts only patch updates within 4.18.x
}
Real-world example A library maintainer accidentally introduces a breaking API change in what was tagged as a minor version release, causing widespread downstream failures for consumers who had reasonably trusted the semver convention that a minor bump wouldn't break their code; the fix involves yanking the release and re-publishing the breaking change as a proper major version instead.

Common follow-ups: What's the practical consequence for downstream consumers when a maintainer violates semver conventions like this?;How do automated tools like semantic-release determine the appropriate version bump automatically based on commit messages?