Two Node-RED instances embeded in the same application

Hello,

I have a Node-RED instance embeded in a Express application using the setup explained here: Embedding into an existing app : Node-RED

But now I want to have another separate Node-RED instance in the same application. The idea is that they will serve to different proposes and have different customizations, but both should be accessed from the same application.

First I tried to simply initiate a new runtime usin different settings values, like the port, endpoint paths and userDir directory, but it didn't work as expected.
After that I did some quick investigation and saw that the node-red module stores some state variables in some kind of singleton pattern, so using the same module to init two instances would not work because one would overwrite the other configuration. So I tried different approaches and the only one I was able to make it work is to duplicate the node-red npm module and use a different one for each new instance, which doesn't seem an ideal solution.

So I wanted to ask if this is the only approach or if there is some alternative that I didn't consider?

Without understanding the detailed requirements, hard to give a definitive answer.

However, I'm not surprised that it doesn't work, even if it did, I doubt it would be a tested or stable method.

However, since Node-RED is perfectly capable of creating its own Express servers, why not simply run 1 or more separate instances and use a communications channel of some sort between them? Node-RED is excellent at supporting many different comms channels so you have quite a choice. HTTP, TCP, UDP, WS, MQTT, ....

Using a reverse proxy as the front-end if you need end users to access your app and Node-RED is recommended so that your users don't have to mess with port numbers. It would also let you define a single security configuration.

Hi @scbp16

The code doesn't support having multiple instances of the whole runtime within a single node.js runtime.

You need to run them as separate processes.

Ok, so what I want to achieve is not supported. Thanks for the replies!

One additional question:
As I said, I was able to use a workaround that seemed to work fine. I basically declared two separated dependencies of the same node-red module:

"dependencies": {
	"node-red-instance-1": "npm:node-red@^3.1.3",
	"node-red-instance-2": "npm:node-red@^3.1.3"
}

And then I required each module individually and started its own instance.

Just wanted to know if you see a big problem with this approach, at least as a temporary solution?

This topic was automatically closed 60 days after the last reply. New replies are no longer allowed.