5 examples of 'check node version' in JavaScript

Every line of 'check node version' code snippets is scanned for vulnerabilities by our powerful machine learning engine that combs millions of open source libraries, ensuring your JavaScript code is secure.

All examples are scanned by Snyk Code

By copying the Snyk Code Snippets you agree to
16function checkNodeVersion() {
17 if (!semver.satisfies(process.version, '>=2.0.0')) {
18 var engine = semver.lt(process.version, '1.0.0') ? 'Node' : 'io.js';
19 var message = 'You are currently running ' + engine + ' ' +
20 process.version + '.\n' +
21 '\n' +
22 'React Native is moving to io.js 2.x. There are several ways to upgrade' +
23 'to io.js depending on your preference.\n' +
24 '\n' +
25 'nvm: nvm install iojs && nvm alias default iojs\n' +
26 'Homebrew: brew unlink node; brew install iojs && brew ln iojs --force\n' +
27 'Installer: download the Mac .pkg from https://iojs.org/\n' +
28 '\n' +
29 'About io.js: https://iojs.org\n' +
30 'Follow along at: https://github.com/facebook/react-native/issues/1737';
31 console.log(formatBanner(message, {
32 chalkFunction: chalk.green,
33 marginLeft: 1,
34 marginRight: 1,
35 paddingBottom: 1,
36 }));
37 }
38}
116async function checkNodeVersion(minimalNodeVersion) {
117 const spinner = ora('Checking node version').start()
118
119 let nodeVersion
120 try {
121 const { stdout } = await exec('node --version')
122 nodeVersion = stdout.trim()
123 } catch (err) {
124 spinner.fail(`node version check failed\n${err}`)
125 throw new Error(err)
126 }
127
128 if (compareVersions(nodeVersion, minimalNodeVersion) === -1) {
129 spinner.fail(
130 `You need Node.js v${minimalNodeVersion} or above but you have v${nodeVersion}`
131 )
132 throw new Error()
133 }
134
135 spinner.succeed(`Node version ${nodeVersion} ${printOk()}`)
136}
3module.exports = function checkNodeVersion(nodeVersion) {
4 var returnOutput = {
5 warn: false,
6 warning: warning
7 };
8 if (nodeVersion) {
9 nodeVersion = nodeVersion.split('.')[0];
10 if (nodeVersion < 1) {
11 returnOutput.warn = true;
12 }
13 }
14 return returnOutput;
15};
178function validateNodeVersion(version) {
179 const [major, minor] = parseSemver(version);
180
181 if (major < 7 || (major === 7 && minor < 6)) {
182 throw new Error(
183 'Running the end-to-end tests requires Node version 7.6.0 or higher.'
184 );
185 }
186}
87static getNodeVersion(): string {
88 return process.versions.node;
89}

Related snippets