Registry / devops / node-version

node-version

JSON →
library4.3.0jsnpmunverified

node-version is a lightweight JavaScript utility designed to parse the current Node.js runtime version (from `process.version`) into a structured object. It provides granular access to major, minor, and patch segments, alongside powerful helper methods for semantic version comparison, such as `isAtLeast`, `isAbove`, `isBelow`, and `isAtMost`. The package, currently at stable version 4.3.0, maintains an active release cadence with minor and patch updates introducing features like `eolDate` and `daysUntilEOL`. Key differentiators include its pure ESM architecture (since v4), full TypeScript support, and built-in checks for Node.js Long Term Support (LTS) status and End-of-Life (EOL) dates, making it an ideal choice for modern Node.js applications that require robust version management and awareness.

npm install node-version
INSTALL
IMPORT
SIG · NODE-VERSION
N
node-version
devopsjavascriptv4.3.0
Install
Import
Disk
Pass rate
0/ 6
Env Coverage0 / 6
glibc
1822
musl
1822
Install & Compatibility
Where this runs
tested against v? · npm install
Install × environment matrix
Each cell = how many times install + import succeeded across repeated harness runs. Partial = flaky.
glibc = Debian/Ubuntu slim · musl = Alpine Linux
musl
node 18226 runs
build_error
glibc
node 18226 runs
build_error
Code
Verified usage

Verified import paths — ran on the pinned version, not inferred.

version
import { version } from 'node-version';
const { version } = require('node-version');
The 'node-version' package is ESM-only since v4.0.0. Using `require()` will result in an `ERR_REQUIRE_ESM` error.
getVersion
import { getVersion } from 'node-version';
const getVersion = require('node-version').getVersion;
This function returns a new `NodeVersion` object instance for the current process, distinct from the pre-instantiated `version` export. It also requires ESM `import`.
NodeVersion
import type { NodeVersion } from 'node-version';
This is a TypeScript type import for type-checking purposes, not a runtime value. It is only relevant in TypeScript projects.

Demonstrates importing the `version` object and accessing its parsed properties and helper methods, including LTS/EOL checks. Also shows `getVersion()`.

import { version, getVersion } from 'node-version'; // Access the pre-instantiated version object console.log('Current Node.js version:', version.long); console.log('Is LTS?', version.isLTS); if (version.isLTS) { console.log('LTS Name:', version.ltsName); } console.log('Is EOL?', version.isEOL); if (version.isEOL) { console.log('End-of-Life Date:', version.eolDate); console.log('Days until EOL:', version.daysUntilEOL); } // Perform version comparisons if (version.isAtLeast('20.0.0')) { console.log('Running on Node.js 20 or newer.'); } else { console.log('Running on an older Node.js version.'); } if (version.isAbove('22.0.0')) { console.log('Running on Node.js strictly above 22.0.0.'); } // Get a new NodeVersion instance const specificVersion = getVersion(); console.log('Another instance (same info):', specificVersion.original);
Debug
Known issues
breakingStarting with v4.0.0, the `node-version` package is exclusively pure ES Module (ESM). CommonJS support has been entirely removed.
fix
Migrate your project to use ES Modules (`import`/`export` syntax) or, if CommonJS is strictly required, pin your dependency to `node-version@3` (`npm install node-version@3`).
affects: >=4.0.0
breakingVersion 4.0.0 and above explicitly require Node.js runtime version 20.0.0 or higher, as specified in the `engines` field.
fix
Ensure your Node.js environment is upgraded to version 20.0.0 or newer. If you must support older Node.js versions, use `node-version@3`.
affects: >=4.0.0
gotchaAttempting to use `require()` to import `node-version` in a CommonJS context will lead to an `ERR_REQUIRE_ESM` error.
fix
Always use `import { symbol } from 'node-version';` for all exports. If you need CommonJS, install `node-version@3`.
affects: >=4.0.0
deprecatedFor applications requiring CommonJS support, version 3.x.x is the last major release that supports `require()`. All subsequent major versions are ESM-only.
fix
If migrating to ESM is not an option, explicitly install `node-version@3` (e.g., `npm install node-version@3`). Be aware that this version may not receive new features or EOL data updates present in v4+.
affects: <4.0.0
Errors
Common errors & fixes
ERR_REQUIRE_ESM: require() of ES Module /path/to/node_modules/node-version/dist/index.js from /your/file.js not supported. Instead change the require of index.js to a dynamic import() or remove the 'type': 'module' in your package.json.
You are attempting to use `require()` to import the `node-version` package, which is an ES Module (ESM) since v4.0.0.
fix
Change your import statement from `const { version } = require('node-version');` to `import { version } from 'node-version';`. Ensure your project or file is configured for ESM (e.g., `"type": "module"` in `package.json` or `.mjs` file extension). If you cannot use ESM, install `node-version@3`.
The engine "node" is incompatible with this module. Expected version ">=20.0.0". Got "18.17.0"
Your current Node.js runtime version does not meet the minimum requirement (`>=20.0.0`) specified by `node-version` v4+.
fix
Upgrade your Node.js environment to version 20.0.0 or newer. Alternatively, if your project must run on an older Node.js version, you can install `node-version@3` which supports earlier Node.js versions.
Upgrade
Version history
4.3.0latest on npm
Audit
Dependencies

No dependency data recorded yet.

Agent activity
2 hits · last 30 days
node
2
Resources
node-version — npm install node-version · libregistry