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'
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:"/red",
httpNodeRoot: "/api",
userDir:"G:/NodeRed",
functionGlobalContext: { } // enables global context
};
// Initialise the runtime with a server and settings
RED.init(server,settings);
// 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);
app.get('***/apiCall***', async(req,res)=>{
try{
**// 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**
}
eventEmitter.emit('stopLocalInstance');
}
catch(e){
console.log(e);
}
}
server.listen(8000);
// Start the runtime
RED.start();