# How to control Node-RED in my Electron application? (start, stop, and restart)

**URL:** <https://discourse.nodered.org/t/how-to-control-node-red-in-my-electron-application-start-stop-and-restart/80083>\
**Category:** General\
**Created:** [26 July 2023 11:48 UTC](https://discourse.nodered.org/t/how-to-control-node-red-in-my-electron-application-start-stop-and-restart/80083 "2023-07-26T11:48:46Z")\
**Posts on this page:** 8\
**Page:** 1

<div class="post-metadata">

**Author:** ![SebCanet](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/sebcanet/32/38069_2.png) [@SebCanet](https://discourse.nodered.org/u/SebCanet)\
**Post date:** [26 July 2023 11:48 UTC](https://discourse.nodered.org/t/how-to-control-node-red-in-my-electron-application-start-stop-and-restart/80083/1 "2023-07-26T11:48:46Z")

</div>

Hello everyone,  
I am developping software to help program microcontroller boards and I have integrated Node-RED into my Electron application to retrieve data sent by my boards ([https://www.youtube.com/watch?v=n9rFr5-rc1E](https://www.youtube.com/watch?v=n9rFr5-rc1E)).  
I used the example code ([https://nodered.org/docs/user-guide/runtime/embedding](https://nodered.org/docs/user-guide/runtime/embedding)) and it works fine, but I would like the user to be able to launch a popup (node-red launches in the background) and close it (and thus close node-red and the express server). This seems impossible...  
If I close Node-RED and try to relaunch it I have this error in console:  
(node:12624) UnhandledPromiseRejectionWarning: TypeError: Cannot read properties of undefined (reading 'forEach')  
at Object.addModule (F:\Travail\STM\cloud\WP6 Training\Studio4Education\Studio4Education\_Electron\_src\node\_modules@node-red\registry\lib\registry.js:195:27)  
at F:\Travail\STM\cloud\WP6 Training\Studio4Education\Studio4Education\_Electron\_src\node\_modules@node-red\registry\lib\loader.js:153:34  
(Use `electron --trace-warnings ...` to show where the warning was created)  
(node:12624) UnhandledPromiseRejectionWarning: Unhandled promise rejection. This error originated either by throwing inside of an async function without a catch block, or by rejecting a promise which was not handled with .catch(). To terminate the node process on unhandled promise rejection, use the CLI flag `--unhandled-rejections=strict` (see [Command-line API | Node.js v20.5.0 Documentation](https://nodejs.org/api/cli.html#cli_unhandled_rejections_mode)). (rejection id: 1)

Thank you very much in advance.

---

<div class="post-metadata">

**Author:** ![MaxBaines](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/maxbaines/32/81476_2.png) [@MaxBaines](https://discourse.nodered.org/u/MaxBaines)\
**Post date:** [26 July 2023 14:07 UTC](https://discourse.nodered.org/t/how-to-control-node-red-in-my-electron-application-start-stop-and-restart/80083/2 "2023-07-26T14:07:35Z")

</div>

A regular in the forum, I've noticed is Dave Conway-Jones (dceejay) who has an old project on Github, [GitHub - dceejay/electron-node-red: Electron Node-RED template](https://github.com/dceejay/electron-node-red) from memory, I think it does similar what you ask, maybe worth a look and an update. Im, also working on a fork of this which will hopefully be public soon.

---

<div class="post-metadata">

**Author:** ![SebCanet](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/sebcanet/32/38069_2.png) [@SebCanet](https://discourse.nodered.org/u/SebCanet)\
**Post date:** [26 July 2023 20:31 UTC](https://discourse.nodered.org/t/how-to-control-node-red-in-my-electron-application-start-stop-and-restart/80083/3 "2023-07-26T20:31:26Z")

</div>

Hello,  
thank you very much, but I'm very familiar with this project and it doesn't totally fit. I manage to launch the Node-RED server and open a secondary window to my electron project. However, I would like to be able to stop the Node-RED server when I close the window, then restart the Node-RED server and the window on demand.

---

<div class="post-metadata">

**Author:** ![hardillb](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/hardillb/32/12373_2.png) [@hardillb](https://discourse.nodered.org/u/hardillb)\
**Post date:** [26 July 2023 21:35 UTC](https://discourse.nodered.org/t/how-to-control-node-red-in-my-electron-application-start-stop-and-restart/80083/4 "2023-07-26T21:35:54Z")

</div>

The Node-RED backend isn't really meant to be restartable.

Why do you want to restart it multiple times in the life time of a single application?

---

<div class="post-metadata">

**Author:** ![SebCanet](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/sebcanet/32/38069_2.png) [@SebCanet](https://discourse.nodered.org/u/SebCanet)\
**Post date:** [27 July 2023 19:09 UTC](https://discourse.nodered.org/t/how-to-control-node-red-in-my-electron-application-start-stop-and-restart/80083/5 "2023-07-27T19:09:14Z")

</div>

It's for educational purpose, so often kids try something, close, reopen, etc.

---

<div class="post-metadata">

**Author:** ![hardillb](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/hardillb/32/12373_2.png) [@hardillb](https://discourse.nodered.org/u/hardillb)\
**Post date:** [27 July 2023 19:27 UTC](https://discourse.nodered.org/t/how-to-control-node-red-in-my-electron-application-start-stop-and-restart/80083/6 "2023-07-27T19:27:54Z")

</div>

But opening/closing a window that just shows the editor, doesn't require the Node-RED backend to be stopped/started each time, it could just run continually in the background.

---

<div class="post-metadata">

**Author:** ![SebCanet](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/sebcanet/32/38069_2.png) [@SebCanet](https://discourse.nodered.org/u/SebCanet)\
**Post date:** [28 July 2023 08:46 UTC](https://discourse.nodered.org/t/how-to-control-node-red-in-my-electron-application-start-stop-and-restart/80083/7 "2023-07-28T08:46:47Z")

</div>

Yes, that's what I do, but it's not a real solution, just we do what we can with Node-RED and its lack of 'good' stop function.If there's a stop, it should be really functionnal I think, and be a 'real' stop, that permits a new start. In short, I'm not sure it's possible.

---

<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:** [26 September 2023 08:47 UTC](https://discourse.nodered.org/t/how-to-control-node-red-in-my-electron-application-start-stop-and-restart/80083/8 "2023-09-26T08:47:15Z")

</div>

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