setup-python/node_modules/please-upgrade-node
Danny McCormick 39c08a0eaa Initial pass
2019-06-26 21:12:00 -04:00
..
.eslintrc.js Initial pass 2019-06-26 21:12:00 -04:00
index.js Initial pass 2019-06-26 21:12:00 -04:00
LICENSE Initial pass 2019-06-26 21:12:00 -04:00
package.json Initial pass 2019-06-26 21:12:00 -04:00
README.md Initial pass 2019-06-26 21:12:00 -04:00

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 the npm 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

Install

npm install please-upgrade-node
#!/usr/bin/env node
const pkg = require('./package.json')
require('please-upgrade-node')(pkg)
// Must run BEFORE requiring other modules
// package.json
{
  "bin": "./bin.js",
  "engines": {
    "node": ">=6"
  }
}

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

Options

You can also pass custom exitCode (default: 1) or message function

pleaseUpgradeNode(pkg, {
  exitCode: 0,
  message: function(requiredVersion) {
    return 'Oops, this program requires 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