# Creating local node red instance

**URL:** <https://discourse.nodered.org/t/creating-local-node-red-instance/62668>\
**Category:** General\
**Created:** [16 May 2022 04:33 UTC](https://discourse.nodered.org/t/creating-local-node-red-instance/62668 "2022-05-16T04:33:12Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![atmar](https://avatars.discourse-cdn.com/v4/letter/a/ecc23a/32.png) [@atmar](https://discourse.nodered.org/u/atmar)\
**Post date:** [16 May 2022 04:33 UTC](https://discourse.nodered.org/t/creating-local-node-red-instance/62668/1 "2022-05-16T04:33:12Z")

</div>

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.

```auto
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

```auto
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);`

```auto
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();`

---

<div class="post-metadata">

**Author:** ![cymplecy](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/cymplecy/32/2773_2.png) [@cymplecy](https://discourse.nodered.org/u/cymplecy)\
**Post date:** [16 May 2022 06:20 UTC](https://discourse.nodered.org/t/creating-local-node-red-instance/62668/2 "2022-05-16T06:20:21Z")

</div>

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

I use

> **[GitHub - TotallyInformation/alternate-node-red-installer: An alternative...](https://github.com/TotallyInformation/alternate-node-red-installer)**
>
> An alternative installer for Node-RED. Avoids global installs, no admin rights required. - GitHub - TotallyInformation/alternate-node-red-installer: An alternative installer for Node-RED. Avoids gl...

for extra instances on lots of my computers

and

> **[Node-RED Desktop](https://sakazuki.github.io/node-red-desktop/)**
>
> Desktop applicaiton of Node-RED. You can get a quick and easy powerful tool.

on my Windows machines

as well as main instances running on 1880

---

<div class="post-metadata">

**Author:** ![atmar](https://avatars.discourse-cdn.com/v4/letter/a/ecc23a/32.png) [@atmar](https://discourse.nodered.org/u/atmar)\
**Post date:** [16 May 2022 06:54 UTC](https://discourse.nodered.org/t/creating-local-node-red-instance/62668/3 "2022-05-16T06:54:52Z")

</div>

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?

---

<div class="post-metadata">

**Author:** ![knolleary](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/knolleary/32/3_2.png) [@knolleary](https://discourse.nodered.org/u/knolleary)\
**Post date:** [16 May 2022 07:35 UTC](https://discourse.nodered.org/t/creating-local-node-red-instance/62668/4 "2022-05-16T07:35:06Z")

</div>

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.

---

<div class="post-metadata">

**Author:** ![system](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/1X/d073cd938eafa2e558d7c2cd59003b3ef4963033.png) [@system](https://discourse.nodered.org/u/system)\
**Post date:** [15 July 2022 07:35 UTC](https://discourse.nodered.org/t/creating-local-node-red-instance/62668/5 "2022-07-15T07:35:53Z")

</div>

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