Security News
Research
Supply Chain Attack on Rspack npm Packages Injects Cryptojacking Malware
A supply chain attack on Rspack's npm packages injected cryptomining malware, potentially impacting thousands of developers.
check-node-version
Advanced tools
The check-node-version npm package is a utility that allows you to check if the current Node.js and npm versions match the specified versions. It is useful for ensuring that your development environment meets the required versions for a project.
Check Node.js version
This feature allows you to check if the current Node.js version meets the specified version requirement. In this example, it checks if the Node.js version is greater than or equal to 10.0.0.
const check = require('check-node-version');
check({ node: '>= 10.0.0' }, (error, result) => {
if (error) {
console.error(error);
return;
}
console.log(result);
});
Check npm version
This feature allows you to check if the current npm version meets the specified version requirement. In this example, it checks if the npm version is greater than or equal to 6.0.0.
const check = require('check-node-version');
check({ npm: '>= 6.0.0' }, (error, result) => {
if (error) {
console.error(error);
return;
}
console.log(result);
});
Check multiple versions
This feature allows you to check multiple version requirements at once. In this example, it checks if both the Node.js version is greater than or equal to 10.0.0 and the npm version is greater than or equal to 6.0.0.
const check = require('check-node-version');
check({ node: '>= 10.0.0', npm: '>= 6.0.0' }, (error, result) => {
if (error) {
console.error(error);
return;
}
console.log(result);
});
The engines package allows you to specify the required versions of Node.js and npm in your package.json file. It is similar to check-node-version but is more focused on defining version requirements within the package.json file rather than programmatically checking them.
The semver package is a library for parsing, validating, and comparing semantic version numbers. While it does not specifically check the current Node.js or npm versions, it can be used to implement similar functionality by comparing version strings.
The node-version-check package is another utility for checking the current Node.js version against a specified version range. It is similar to check-node-version but is more lightweight and focused solely on Node.js version checking.
Check installed versions of node
and npm
.
npm install check-node-version
SYNOPSIS
check-node-version [OPTIONS]
DESCRIPTION
check-node-version will check if the current node and npm versions
match the given semver version ranges.
If the given version is not satisfied, information about
installing the needed version is printed and the program exits
with an error code.
OPTIONS
--node VERSION
Check that the current node version matches the given semver
version range.
--npm VERSION
Check that the current npm version matches the given semver
version range.
-q, --quiet
Don't output anything. Exit with an error code if the node
or npm version is not satisfied, otherwise exit with code 0.
-h, --help
Print a usage message.
When no versions are given, the current node and npm versions are printed out.
$ check-node-version
node: v0.12.7
npm: v2.14.10
$ echo $?
0
node@4
and npm@2.14
$ check-node-version --node 4 --npm 2.14
node: v0.12.7
npm: v2.14.10
Error: Wanted node version "4" (>=4.0.0 <5.0.0)
To install node, run `nvm install 4` or check https://nodejs.org/
$ echo $?
1
npm test
{
"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 from node. See index.js
and test.js
for more information.n
FAQs
Check installed versions of node and npm
The npm package check-node-version receives a total of 139,095 weekly downloads. As such, check-node-version popularity was classified as popular.
We found that check-node-version demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 1 open source maintainer collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Security News
Research
A supply chain attack on Rspack's npm packages injected cryptomining malware, potentially impacting thousands of developers.
Research
Security News
Socket researchers discovered a malware campaign on npm delivering the Skuld infostealer via typosquatted packages, exposing sensitive data.
Security News
Sonar’s acquisition of Tidelift highlights a growing industry shift toward sustainable open source funding, addressing maintainer burnout and critical software dependencies.