Node.js Version Upgrade Prompt

3.2.0 · active · verified Sun Apr 19

Please-upgrade-node is a focused utility designed to display a clear, beginner-friendly message to users when their Node.js version does not meet the minimum requirement specified in a project's `package.json` `engines.node` field. Instead of generic stack traces, it provides actionable advice to upgrade Node.js. The package is currently at version 3.2.0, with a recent update adding TypeScript definitions, indicating active maintenance. It is specifically built for CLI applications to enhance user experience by gracefully handling Node.js version incompatibilities. A key differentiator is its strict support for only the `>=` operator in the `engines.node` field, simplifying configuration while ensuring explicit minimum version requirements. Its release cadence is sporadic, tied to feature additions or bug fixes, rather than a fixed schedule.

Common errors

Warnings

Install

Imports

Quickstart

This example demonstrates how to install and integrate `please-upgrade-node` at the very beginning of a CLI application to ensure the user's Node.js version meets the `engines.node` requirement from `package.json`, showing a custom message and exiting if not met.

import * as fs from 'node:fs';
import * as path from 'node:path';

const pkgPath = path.join(process.cwd(), 'package.json');
const pkg = JSON.parse(fs.readFileSync(pkgPath, 'utf8'));

// Create a dummy package.json for demonstration if it doesn't exist
if (!fs.existsSync(pkgPath)) {
  fs.writeFileSync(pkgPath, JSON.stringify({
    name: 'my-cli-app',
    version: '1.0.0',
    engines: {
      node: '>=18'
    }
  }, null, 2));
  console.log('Created a dummy package.json with engines.node >=18');
}

// IMPORTANT: Must run BEFORE requiring any other modules that might use newer Node.js features
require('please-upgrade-node')(pkg, {
  message: (requiredVersion) => `\n🚧 Oh no! This application requires Node.js ${requiredVersion} or higher.\n   You are currently running Node.js ${process.version}.\n   Please upgrade your Node.js version to continue.\n`,
  exitCode: 1 // Default behavior is to exit with code 1
});

// If Node.js version is sufficient, continue with your application logic
console.log(`
🎉 Node.js version ${process.version} is sufficient. Running application...\n`);
// Your actual application code would follow here

view raw JSON →