{"gitdown": "badge", "name": "npm-version"} {"gitdown": "badge", "name": "appveyor"} {"gitdown": "badge", "name": "travis"}
Check installed versions of node, npm, npx, yarn, and pnpm.
{"gitdown": "contents"}
npm install check-node-version{"gitdown": "include", "file": "./usage.txt"}
Check for node 6, but have 8.2.1 installed.
$ check-node-version --node 6
node: 8.2.1
Error: Wanted node version 6 (>=6.0.0 <7.0.0)
To install node, run `nvm install 6` or see https://nodejs.org/
$ echo $?
1If all versions match, there is no output:
$ check-node-version --node 6
$ echo $?
0You can check versions of any combinations of node, npm, npx, yarn, and pnpm
at one time.
$ check-node-version --node 4 --npm 2.14 --npx 6 --yarn 0.17.1 --pnpm 6.20.1You can check versions pinned by Volta:
$ check-node-version --voltaUse the --print option to print currently installed versions.
If given a tool to check, only that will be printed.
Otherwise, all known tools will be printed.
Notes a missing tool.
$ check-node-version --print --node 11.12
node: 11.12.0
$ echo $?
0$ check-node-version --print
yarn: not found
node: 11.12.0
npm: 6.9.0
npx: 10.2.0
$ $LASTEXITCODE
0NOTE: Both preceding examples show that this works equally cross-platform, the first one being a *nix shell, the second one running on Windows.
NOTE: As per Issue 36, non-semver-compliant versions (looking at yarn here) will be handled similarly to missing tools, just with a different error message.
At the time of writing, we think that
- all tools should always use semver
- exceptions are bound too be very rare
- preventing a crash is sufficient
Consequently, we do not intend to support non-compliant versions to any further extent.
$ check-node-version --node $(cat .nvmrc) --npm 2.14{
"name": "my-package",
"devDependencies": {
"check-node-version": "^1.0.0"
},
"scripts": {
"test": "check-node-version --node '>= 4.2.3' && node my-tests.js"
}
}This module can also be used programmatically.
Pass it an object with the required versions of node, npm, npx, yarn and/or pnpm followed by a results handler.
const check = require("check-node-version");
check(
{ node: ">= 18.3", },
(error, result) => {
if (error) {
console.error(error);
return;
}
if (result.isSatisfied) {
console.log("All is well.");
return;
}
console.error("Some package version(s) failed!");
for (const packageName of Object.keys(result.versions)) {
if (!result.versions[packageName].isSatisfied) {
console.error(`Missing ${packageName}.`);
}
}
}
);See index.d.ts for the full input and output type definitions.