I am using a RPi 4 to monitor the air quality of rooms. I have built a Node-red flow that processes and sends the output via MQTT. I start the node-red flow by SSH. The problem is that although the RPi is connected to WiFi the MQTT connection is disturbed as soon as I change the WiFi or close the terminal in my Laptop.
Is there is way to activate the Node-red flow once via SSH and then keep the Node-red flow running even after closing the terminal in laptop.
Nicks information on running as a service is best.
But you can also run it as you've outlined simply by installing TMUX, SCREEN or BYOBU. Start a session when you log in, start NR in that session then you can kill your SSH connection. Next SSH login, you can reconnect to the still running session. You can also configure to auto-reconnect. Personally, I prefer Byobu but any of the 3 will work.
This also has the advantage that you can leave other long-running commands going. Especially useful if you are mobile or have a unreliable connection.