Node.js Modern Version Detector

1.0.0 · abandoned · verified Sun Apr 19

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

Warnings

Install

Imports

Quickstart

Demonstrates both programmatic and conceptual CLI usage of `is-node-modern`, highlighting the need to specify a modern version threshold due to the package's outdated defaults.

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.');

view raw JSON →