3e028b77cf5ee00c3fb87b05a11fa9140cef958e839d867dc7eb405e42fb3a528cd7d0c73696b5ce872c741de72cec2f687bd08b1d178732362c27edb4b59b 2.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172
  1. # Please upgrade Node [![](http://img.shields.io/npm/dm/please-upgrade-node.svg?style=flat)](https://www.npmjs.org/package/please-upgrade-node) [![Build Status](https://travis-ci.org/typicode/please-upgrade-node.svg?branch=master)](https://travis-ci.org/typicode/please-upgrade-node) [![npm](https://img.shields.io/npm/v/please-upgrade-node.svg)](https://www.npmjs.com/package/please-upgrade-node)
  2. > :information_desk_person: show a message to your users to upgrade Node instead of a stacktrace
  3. 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.
  4. ```sh
  5. $ node -v
  6. 0.12
  7. $ modern-cli
  8. modern-cli requires at least version 6 of Node, please upgrade
  9. ```
  10. ## Support
  11. If you like this project, you can support me on [GitHub Sponsors](https://github.com/users/typicode/sponsorship)
  12. ## Usage
  13. ```sh
  14. npm install please-upgrade-node
  15. ```
  16. Add `please-upgrade-node` at the top of your CLI
  17. ```js
  18. #!/usr/bin/env node
  19. const pkg = require('./package.json')
  20. require('please-upgrade-node')(pkg) // <- Must run BEFORE requiring any other modules
  21. // ...
  22. ```
  23. Set in your `package.json` the required Node version
  24. ```js
  25. {
  26. "engines": {
  27. "node": ">=6"
  28. }
  29. }
  30. ```
  31. __Important__: `>=` is the only operator supported by `please-upgrade-node` (e.g. `>=6`, `>=6.0`, `>=6.0.0`).
  32. ## Options
  33. You can set custom `exitCode` and `message` function if needed
  34. ```js
  35. pleaseUpgradeNode(pkg, {
  36. exitCode: 0, // Default: 1
  37. message: function(requiredVersion) {
  38. return 'Oops this program require Node ' + requiredVersion
  39. }
  40. })
  41. ```
  42. __Important__: to keep `message` function compatible with older versions of Node, avoid using ES6 features like `=>` or string interpolation.
  43. ## See also
  44. * [pkg-ok](https://github.com/typicode/pkg-ok) - :ok_hand: Prevents publishing a module with bad paths
  45. * [husky](https://github.com/typicode/husky) - :dog: Git hooks made easy
  46. * [update-notifier](https://github.com/yeoman/update-notifier) - Update notifications for your CLI app
  47. Thanks to [zeit/serve](https://github.com/zeit/serve) for the error message inspiration.
  48. ## License
  49. MIT - [Typicode :cactus:](https://github.com/typicode) - [Patreon](https://patreon.com/typicode)