How to embed multiple instances of node-red in node app

浪子不回头ぞ 提交于 2019-12-04 12:11:07

No, currently Node-RED has no multi-user capabilities and no way to instantiate multiple instances in one process.

You'll have to run separate instances of the application for each user. Have a look at something like FRED for an example of this. This runs individual instances and proxies them to make the integration look like it's all on the same port/domain

If you're interested I created a fork of the node-red project allowing this feature.

this is how you would initiate it:

var http = require('http');
var express = require("express");
var RED = require("node-red")();
var RED2 = require("node-red")();

// Create an Express app
var app = express();

// Add a simple route for static content served from 'public'
app.use("/",express.static("public"));


// Create a server
var server = http.createServer(app);


// Create the settings object - see default settings.js file for other options
var settings = {
    httpAdminRoot:"/red1",
    httpNodeRoot: "/api",
    userDir:"./hhh",
    functionGlobalContext: { }    // enables global context
};



// Initialise the runtime with a server and settings

RED.init(server,settings);

console.log(RED2.settings === RED.settings, 888, RED2.settings.userSettings);

// Serve the editor UI from /red
app.use(settings.httpAdminRoot,RED.httpAdmin);


// Serve the http nodes UI from /api
app.use(settings.httpNodeRoot,RED.httpNode);


server.listen(8005);


// Start the runtime
RED.start();


var app2 = express();
app2.use("/",express.static("public"));
var server2 = http.createServer(app2);
var settings2 = {
    httpAdminRoot:"/red2",
    httpNodeRoot: "/api",
    userDir:"./hhhh",
    functionGlobalContext: { }
};

RED2.init(server2,settings2);
app2.use(settings2.httpAdminRoot,RED2.httpAdmin);
app2.use(settings2.httpNodeRoot,RED2.httpNode);



RED2.start();
server2.listen(8006);

console.log(RED.settings.httpAdminRoot);
console.log(RED2.settings.httpAdminRoot);
console.log(RED2.settings === RED.settings);

also, works on the same port. but make sure to use different paths is so.

https://github.com/aryeharmon/node-red

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!