From f699516fdbdc887113bad144b58ee600898a8e93 Mon Sep 17 00:00:00 2001 From: Nick O'Leary Date: Thu, 12 Jan 2017 10:40:04 +0000 Subject: [PATCH] Add node.js version check on startup --- red.js | 5 ++++- red/red.js | 10 ++++++++++ 2 files changed, 14 insertions(+), 1 deletion(-) diff --git a/red.js b/red.js index 35da1c71a..e80de12a6 100755 --- a/red.js +++ b/red.js @@ -175,7 +175,10 @@ if (parsedArgs.userDir) { try { RED.init(server,settings); } catch(err) { - if (err.code == "not_built") { + if (err.code == "unsupported_version") { + console.log("Unsupported version of node.js:",process.version); + console.log("Node-RED requires node.js v4 or later"); + } else if (err.code == "not_built") { console.log("Node-RED has not been built. See README.md for details"); } else { console.log("Failed to start server:"); diff --git a/red/red.js b/red/red.js index 52c7ec1ca..32186508c 100644 --- a/red/red.js +++ b/red/red.js @@ -27,6 +27,15 @@ var adminApp = null; var server = null; var apiEnabled = false; +function checkVersion() { + var semver = require('semver'); + if (!semver.satisfies(process.version,">=4.0.0")) { + var e = new Error("Unsupported version of node.js"); + e.code = "unsupported_version"; + throw e; + } +} + function checkBuild() { var editorFile = path.resolve(path.join(__dirname,"..","public","red","red.min.js")); try { @@ -46,6 +55,7 @@ module.exports = { } if (!userSettings.SKIP_BUILD_CHECK) { + checkVersion(); checkBuild(); }