How to stop Node-RED in my Electron application? (RED.stop() command doesn't stop anything)

Hello everyone,
I am developping software to help program microcontroller boards and I want to integrate Node-RED into my Electron application to retrieve data sent by my boards.
I used the example code (https://nodered.org/docs/user-guide/runtime/embedding ) and it works fine, but I can't find how to stop the Node-Red runtime (the RED.stop() command doesn't stop anything) or even the express server. I have the impression that it's the same solution everywhere: close the application window. But this is not a solution in my opinion...
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...
I tried to list the connections to close them one by one but it doesn't work, I tried to replace Express with Fastify but the problem is the same. In short....HELLLLPPP !!!!
Thank you very much in advance.

Are you using MQTT?

Then it might be related to this issue:

Thanks a lot for answering, but it occurs even doing nothing. I lanuch it in Electron window, a 2nd from my mainwindow, and when I close this Electron window server is still running and still can use it with a browser and connect to it.
I would like to be able to stop it comepletely without closing my main application.