Skip to content
💁 Show a message to your users to upgrade Node instead of a stacktrace
JavaScript
Branch: master
Clone or download
Latest commit cf4e00d Aug 8, 2019
Permalink
Type Name Latest commit message Commit time
Failed to load latest commit information.
.github Create FUNDING.yml Jul 29, 2019
.eslintrc.js Add eslint and prettier Apr 27, 2018
.gitignore first commit Jul 8, 2017
.npmignore first commit Jul 8, 2017
.travis.yml first commit Jul 8, 2017
LICENSE first commit Jul 8, 2017
README.md update README.md Aug 8, 2019
index.d.ts format Aug 8, 2019
index.js Fix bug with exitCode being 0 but exiting with 1 Jul 5, 2018
package-lock.json 3.2.0 Aug 8, 2019
package.json 3.2.0 Aug 8, 2019
test.js Fix bug with exitCode being 0 but exiting with 1 Jul 5, 2018

README.md

Please upgrade Node Build Status npm

💁 show a message to your users to upgrade Node instead of a stacktrace

It's common for new Node users to miss or not understand engines warning when installing a CLI. This package displays a beginner-friendly message if their Node version is below the one expected.

$ node -v
0.12

$ modern-cli
modern-cli requires at least version 6 of Node, please upgrade

Support

If you like this project, you can support me on GitHub Sponsors

Usage

npm install please-upgrade-node

Add please-upgrade-node at the top of your CLI

#!/usr/bin/env node
const pkg = require('./package.json')
require('please-upgrade-node')(pkg) // <- Must run BEFORE requiring any other modules

// ...

Set in your package.json the required Node version

{
  "engines": {
    "node": ">=6"
  }
}

Important: >= is the only operator supported by please-upgrade-node (e.g. >=6, >=6.0, >=6.0.0).

Options

You can set custom exitCode and message function if needed

pleaseUpgradeNode(pkg, {
  exitCode: 0, // Default: 1
  message: function(requiredVersion) {
    return 'Oops this program require Node ' +  requiredVersion
  }
})

Important: to keep message function compatible with older versions of Node, avoid using ES6 features like => or string interpolation.

See also

  • pkg-ok - 👌 Prevents publishing a module with bad paths
  • husky - 🐶 Git hooks made easy
  • update-notifier - Update notifications for your CLI app

Thanks to zeit/serve for the error message inspiration.

License

MIT - Typicode 🌵 - Patreon

You can’t perform that action at this time.