Add node.js version check on startup

This commit is contained in:
Nick O'Leary 2017-01-12 10:40:04 +00:00
parent ca5cbb640a
commit f699516fdb
No known key found for this signature in database
GPG Key ID: 4F2157149161A6C9
2 changed files with 14 additions and 1 deletions

5
red.js
View File

@ -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:");

View File

@ -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();
}