Node.js Modern Version Detector
This package, `is-node-modern`, provides a utility to programmatically or via CLI determine if the current Node.js environment meets a specified "modern" version threshold. It's currently at version 1.0.0, released during an era when Node.js versions 0.10 through 6.x were prevalent. While it allows for custom version thresholds, its default "modern" check is based on outdated LTS definitions, rendering it largely irrelevant for contemporary Node.js development without explicit configuration. Given its initial and sole release, along with the age of the Node.js versions it was designed for, the package is considered abandoned, lacking ongoing maintenance or updates for modern Node.js ecosystems. It offers a simple programmatic API (`require('is-node-modern')`) and a CLI command (`is-node-modern`) primarily for conditional execution in `package.json` scripts.
Common errors
-
is-node-modern: command not found
cause The `is-node-modern` executable is not in the system's PATH or `npm run` context, typically because it wasn't installed or installed incorrectly.fixEnsure `is-node-modern` is listed in your `devDependencies` in `package.json` and executed via `npm run <script-name>`. For global CLI usage (generally discouraged for project dependencies), install it with `npm install -g is-node-modern`. -
TypeError: isNodeModern is not a function
cause Attempting to use `isNodeModern` as a named export or assuming it's an object with methods, or trying to `import isNodeModern from 'is-node-modern'` in an ES Module context.fixUse the CommonJS `require` syntax: `const isNodeModern = require('is-node-modern');` and call it as a default function: `if (isNodeModern())` or `if (isNodeModern(16))`. -
Unexpected behavior: `is-node-modern` (without argument) reports Node.js 18 as *not* modern.
cause The package's internal default threshold for 'modern' is based on Node.js LTS versions from approximately 2016-2018 (e.g., v4 or v6), which are now very old.fixAlways provide a specific version threshold as an argument for current Node.js versions, e.g., `is-node-modern 18` in the CLI or `isNodeModern(18)` in your code.
Warnings
- gotcha The package's default definition of 'modern' Node.js is based on LTS versions from around the Node.js 4.x-6.x era (circa 2016-2018). Using `isNodeModern()` programmatically or `is-node-modern` without a specific version argument will likely result in false negatives for genuinely modern Node.js runtimes (e.g., Node.js 16+).
- breaking This package is at its initial v1.0.0 release and appears to be unmaintained. Its build badges reference Node.js versions 0.10-6.x, indicating it was developed and last updated almost a decade ago. It is considered abandoned.
- gotcha The package exclusively uses CommonJS (`require`). There is no native ES Module (ESM) support, and attempting to `import` it directly in an ESM context will lead to errors without a transpilation step or a CommonJS wrapper.
Install
-
npm install is-node-modern -
yarn add is-node-modern -
pnpm add is-node-modern
Imports
- isNodeModern
import { isNodeModern } from 'is-node-modern'; import isNodeModern from 'is-node-modern';const isNodeModern = require('is-node-modern');
Quickstart
const isNodeModern = require('is-node-modern');
// Check if the current Node.js version is considered modern by the package's default threshold.
// WARNING: This default is based on very old Node.js LTS versions (e.g., v4 or v6) and will
// likely return false for genuinely modern Node.js versions (e.g., Node.js 18+).
if (isNodeModern()) {
console.log(`Node.js ${process.versions.node} is considered modern by the default (outdated) definition.`);
} else {
console.log(`Node.js ${process.versions.node} is NOT considered modern by the default definition.`);
}
// To check against a specific, more relevant Node.js version (e.g., Node.js 16 or newer)
const MIN_MODERN_VERSION = 16;
if (isNodeModern(MIN_MODERN_VERSION)) {
console.log(`Node.js version ${process.versions.node} is at or above v${MIN_MODERN_VERSION}.`);
// Example: Execute a task or load a module only if Node.js is modern enough
// try {
// const { someModernFeature } = require('some-modern-only-lib');
// someModernFeature();
// } catch (error) {
// console.error('Failed to use modern feature:', error.message);
// }
} else {
console.log(`Node.js version ${process.versions.node} is below v${MIN_MODERN_VERSION}. Skipping modern-only actions.`);
}
console.log('\n--- CLI Usage Example (typically in package.json scripts) ---');
console.log('// In your package.json, under "scripts":');
console.log('// "my-action": "is-node-modern 18 && echo \"Running modern action (Node 18+)\" || echo \"Skipping, Node version too old\""');
console.log(`// Current Node version: ${process.versions.node}`);
console.log('// If Node.js >= 18, the first command runs. Otherwise, the second runs.');