{"id":11461,"library":"node-version","title":"Node.js Version Utility","description":"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.","status":"active","version":"4.3.0","language":"javascript","source_language":"en","source_url":"https://github.com/srod/node-version","tags":["javascript","node","version","runtime","environment","semver","typescript"],"install":[{"cmd":"npm install node-version","lang":"bash","label":"npm"},{"cmd":"yarn add node-version","lang":"bash","label":"yarn"},{"cmd":"pnpm add node-version","lang":"bash","label":"pnpm"}],"dependencies":[],"imports":[{"note":"The 'node-version' package is ESM-only since v4.0.0. Using `require()` will result in an `ERR_REQUIRE_ESM` error.","wrong":"const { version } = require('node-version');","symbol":"version","correct":"import { version } from 'node-version';"},{"note":"This function returns a new `NodeVersion` object instance for the current process, distinct from the pre-instantiated `version` export. It also requires ESM `import`.","wrong":"const getVersion = require('node-version').getVersion;","symbol":"getVersion","correct":"import { getVersion } from 'node-version';"},{"note":"This is a TypeScript type import for type-checking purposes, not a runtime value. It is only relevant in TypeScript projects.","symbol":"NodeVersion","correct":"import type { NodeVersion } from 'node-version';"}],"quickstart":{"code":"import { version, getVersion } from 'node-version';\n\n// Access the pre-instantiated version object\nconsole.log('Current Node.js version:', version.long);\nconsole.log('Is LTS?', version.isLTS);\nif (version.isLTS) {\n  console.log('LTS Name:', version.ltsName);\n}\nconsole.log('Is EOL?', version.isEOL);\nif (version.isEOL) {\n    console.log('End-of-Life Date:', version.eolDate);\n    console.log('Days until EOL:', version.daysUntilEOL);\n}\n\n// Perform version comparisons\nif (version.isAtLeast('20.0.0')) {\n  console.log('Running on Node.js 20 or newer.');\n} else {\n  console.log('Running on an older Node.js version.');\n}\n\nif (version.isAbove('22.0.0')) {\n  console.log('Running on Node.js strictly above 22.0.0.');\n}\n\n// Get a new NodeVersion instance\nconst specificVersion = getVersion();\nconsole.log('Another instance (same info):', specificVersion.original);","lang":"typescript","description":"Demonstrates importing the `version` object and accessing its parsed properties and helper methods, including LTS/EOL checks. Also shows `getVersion()`."},"warnings":[{"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`).","message":"Starting with v4.0.0, the `node-version` package is exclusively pure ES Module (ESM). CommonJS support has been entirely removed.","severity":"breaking","affected_versions":">=4.0.0"},{"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`.","message":"Version 4.0.0 and above explicitly require Node.js runtime version 20.0.0 or higher, as specified in the `engines` field.","severity":"breaking","affected_versions":">=4.0.0"},{"fix":"Always use `import { symbol } from 'node-version';` for all exports. If you need CommonJS, install `node-version@3`.","message":"Attempting to use `require()` to import `node-version` in a CommonJS context will lead to an `ERR_REQUIRE_ESM` error.","severity":"gotcha","affected_versions":">=4.0.0"},{"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+.","message":"For applications requiring CommonJS support, version 3.x.x is the last major release that supports `require()`. All subsequent major versions are ESM-only.","severity":"deprecated","affected_versions":"<4.0.0"}],"env_vars":null,"last_verified":"2026-04-19T00:00:00.000Z","next_check":"2026-07-18T00:00:00.000Z","problems":[{"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`.","cause":"You are attempting to use `require()` to import the `node-version` package, which is an ES Module (ESM) since v4.0.0.","error":"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."},{"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.","cause":"Your current Node.js runtime version does not meet the minimum requirement (`>=20.0.0`) specified by `node-version` v4+.","error":"The engine \"node\" is incompatible with this module. Expected version \">=20.0.0\". Got \"18.17.0\""}],"ecosystem":"npm"}