# Stop and start node red programmatically

**URL:** https://discourse.nodered.org/t/stop-and-start-node-red-programmatically/30270
**Category:** General
**Created:** [17 July 2020 16:43 UTC](https://discourse.nodered.org/t/stop-and-start-node-red-programmatically/30270 "2020-07-17T16:43:11Z")
**Posts on this page:** 3
**Page:** 1

<div class="post-metadata">

### Author: ![premalatha-b](https://avatars.discourse-cdn.com/v4/letter/p/278dde/32.png) [@premalatha-b](https://discourse.nodered.org/u/premalatha-b)
#### Post date: [17 July 2020 16:43 UTC](https://discourse.nodered.org/t/stop-and-start-node-red-programmatically/30270/1 "2020-07-17T16:43:11Z")

</div>

I have embedded nodered in electron app.  
Have started the node red. ( programmatically using RED.start()), now i want to restart it.  
trying to use RED.stop.then(()=\>RED.start());  
it is giving error like  
Potentially unhandled rejection [1] TypeError: Cannot read property 'forEach' of undefined  
at Object.addModule (...\node\_modules@node-red\registry\lib\registry.js:199:27)  
It seems it is trying to load opcua node modules and it is giving this error.

When node red started first time programmatically, i didn't get this error, when i stop and then start I get this error.

Can idea how to handle this

- Any other way to restart node red programmatically?
- Am i doing anything wrong? please correct me
-

---

<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: [17 July 2020 17:45 UTC](https://discourse.nodered.org/t/stop-and-start-node-red-programmatically/30270/2 "2020-07-17T17:45:37Z")

</div>

The RED.stop/start API does not currently work well with doing multiple restarts of the the runtime without also restarting the Node.js process. It just isn't the primary use case as Node-RED is normally a self-contained long running process.

It would be good to get it working - but I suspect it will need more testing and development work to get it working.

---

<div class="post-metadata">

### Author: ![Verschnupft](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/verschnupft/32/76388_2.png) [@Verschnupft](https://discourse.nodered.org/u/Verschnupft)
#### Post date: [19 February 2023 16:42 UTC](https://discourse.nodered.org/t/stop-and-start-node-red-programmatically/30270/3 "2023-02-19T16:42:55Z")

</div>

Hey,  
I just encountered a similar problem and was wondering if the API now supports this functionality (restarting without restarting the Node.js process).
