node-semver implements Semantic Versioning parsing, comparison, and range matching for Node programs. npm uses this module for dependency version logic, and it also ships a small CLI.
Overview
node-semver is the reference JavaScript implementation of SemVer operations used throughout the npm ecosystem. It parses version strings, compares versions, satisfies range expressions, coerces loose strings, and increments prerelease components.
The API covers comparators, hyphen ranges, carets, tildes, and advanced desugaring rules aligned with the SemVer 2.0.0 specification. Functions can be imported individually for tree-shaking, while the main entry lazy-loads submodules.
Prerelease handling defaults to excluding prereleases from range matches unless includePrerelease is set, mirroring npm's safety model for unstable builds. Utilities include clean(), diff(), intersects(), and truncate() for manipulating version tuples.
The same package installs a command-line utility for shell scripts that need version checks outside JavaScript code.
Key features
- SemVer parse and compare helpers
- Range satisfaction and intersection
- Prerelease-aware matching options
- Version coercion from loose strings
- Modular function imports
- CLI for shell workflows
- Constants for release types
Use cases
- npm-style dependency range checks
- Release automation version bumps
- CI gates on compatible version ranges