Creating local node red instance

how should I create local node red instance in below 'apiCall' request? also I want global instance of created node red instance to be running in the background.

var http = require('http');
var express = require("express");
var RED = require("node-red");
var events = require("events");
var eventEmitter = new events.EventEmitter();

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

// Add a simple route for static content served from 'public'

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

// Create the settings object - see default settings.js file for other options

var settings = {
    httpNodeRoot: "/api",
    functionGlobalContext: { }    // enables global context

// Initialise the runtime with a server and settings

// Serve the editor UI from /red

// Serve the http nodes UI from /api

app.get('***/apiCall***', async(req,res)=>{
	**// Here I want to start the new local red-node instance**
	eventEmitter.on('stopLocalInstance', async()=>
		**// Here I want to stop the local red-node instance**


// Start the runtime

I don't know anything about helping you directly with the way your trying to do it

I use

for extra instances on lots of my computers


on my Windows machines

as well as main instances running on 1880

Thanks for response! I have embedded my node red into diff application and for that I want one global instance to be running until I stop it manually but there should be another local instance needs to be created only on api call and that particular instance should be stopped on eventEmitter.emit('stopLocalInstance').
So for that what changes do I need to do in my uploaded code?

The short answer is you cannot have two node-red instances running the same node.js process - it simply isn't designed to work like that.

You could run a second instance as a separate process - have a look at the child_process docs of node.js to see how to run external processes from node.js code.

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