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

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).
I used the example code (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). (rejection id: 1)

Thank you very much in advance.

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 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.

1 Like

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.

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?

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

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.

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.

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