nodejs-version-checker
v1.2.0
Published
Check NodeJS and npm version installed locally
Downloads
18
Maintainers
Readme
NodeJS Version Checker
This module allows you to check and compare versions of NodeJS and npm.
Compatibility
The minimum supported version of Node.js is v6.
Usage
Installation
$ npm i nodejs-version-checker
Importing
const nodeJSVersionChecker = require("nodejs-version-checker");
Example
const nodeJSVersionChecker = require("nodejs-version-checker");
//Node version <=6.x.x
nodeJSVersionChecker({ node: "6.17.1", npm: "3.10.0"})
.then((result) => {
console.log(result);
})
.catch((error) => console.error(error));
//Node version >=6.x.x
(async () => {
try {
const result = await nodeJSVersionChecker();
console.log(result);
} catch (error) {
console.error(error);
}
})();
-----------------------------------------------------
nodeJSVersionChecker({ node: "6.17.1"})
.then((result) => {
console.log(result);
})
.catch((error) => console.error(error));
-----------------------------------------------------
nodeJSVersionChecker("6.17.1")
.then((result) => {
console.log(result);
})
.catch((error) => console.error(error));
-----------------------------------------------------
nodeJSVersionChecker()
.then((result) => {
console.log(result);
})
.catch((error) => console.error(error));
Output
{ node:
{ current: '8.17.1',
expected: '6.17.1',
comparison: 1,
comparisonString: 'greater' },
npm:
{ current: '3.5.10',
expected: '3.10.0',
comparison: -1,
comparisonString: 'less' } }
-----------------------------------------------------
{ node:
{ current: '6.17.1',
expected: '6.17.1',
comparison: 0,
comparisonString: 'equal' } }
-----------------------------------------------------
{ node:
{ current: '6.17.1',
expected: '6.17.1',
comparison: 0,
comparisonString: 'equal' } }
-----------------------------------------------------
// Default result if no parameters is passed
{ node: { current: '6.17.1' } }
Comparison mapping
comparison: 0
: The local version is equal to the one expectedcomparison: 1
: The local version is greater than the one expectedcomparison: -1
: The local version is less than the one expected- If the key does not appear, it means that a comparison parameter was not passed