please-upgrade-npm
v3.2.3
Published
Displays a beginner-friendly message telling your user to upgrade their version of npm
Downloads
6
Maintainers
Readme
Please upgrade npm
supporting semver checking, forked from [email protected]
:information_desk_person: show a message to your users to upgrade npm 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 npm version is below the one expected.
$ npm -v
5.1.1
$ modern-cli
modern-cli requires 6 version of npm, please upgrade
Usage
npm install please-upgrade-npm
Add please-upgrade-npm
at the top of your CLI
#!/usr/bin/env node
const pkg = require('./package.json')
require('please-upgrade-npm')(pkg) // <- Must run BEFORE requiring any other modules
// ...
Set in your package.json
the required Node version
{
"engines": {
"npm": ">=6"
}
}
Options
You can set custom exitCode
and message
function if needed
pleaseUpgradeNpm(pkg, {
exitCode: 0, // Default: 1
message: function(requiredVersion) {
return 'Oops this program require npm ' + requiredVersion
}
})
Important: to keep message
function compatible with older versions of Node, avoid using ES6 features like =>
or string interpolation.