Recently I experienced the dreaded 502 Bad Gateway problem in Node-RED. It happened after a minor edit in an existing Node-RED flow. The common fixes of changing SSL and credential_secret settings didn’t help, nor did clearing browser caches. Restoring backups from well before the problem occurred did not help. The log file showed a strange UnhandledPromiseRejection error.
If I uninstalled Node-RED and rebooted host, Node-RED would load up but of course without any of my flows or custom nodes. About 95% of my automations are in Node-RED, and I have quite a few, so re-creating all my flows was not a welcome idea. I knew from posts that I could re-import my flows but didn’t find any clear directions to do so, or indications of how complete a rebuild an import provides. Anyway, in case it helps anyone in a similar situation here’s the steps I took:
- Remove Node-RED addon.
- Rename node-red folder to node-red-old.
- Reboot host (not just restart Home Assistant). Currently in Settings, System, Hardware, three dots in the upper right corner, Reboot host.
- Install Node-RED addon.
- Restart Home Assistant. Currently in Settings, System, Restart in upper right corner.
- Configure Node-RED addon with startup toggle settings, credential_secret and proper SSL setting, and Save.
- Start Node-RED addon and check on UI that it is running properly.
- Import your old flows from the flows.json file in node-red-old folder.
- Use text editor to open package.json in node-red-old folder. Read the list of dependencies which are the node names and versions that you will need to add in the Node-RED pallette. Install those using Manage Pallette in Node-RED.
- Restart Home Assistant.
- Load Node-RED UI to verify all is well.
- Delete or preserve in a backup location the node-red-old folder.
Further lessons:
- After importing my flows and reinstalling ALL the nodes I had previously loaded I still had a 502 Bad Gateway - ouch! Eight of the 36 nodes I had installed were “experimental” nodes for me to test how they worked but were not used in my working flows. So on my second try I loaded only the nodes that were being used. And the nodes I did load, I loaded in small groups and restarted in between groups to be sure I didn’t get the 502 again. My assumption is that one of those “experimental” nodes introduced instability, perhaps during an update of the node.
- If you are missing a required node, Node-RED will give you a warning that flows cannot be fully loaded because of missing nodes. The warning will give you a good indication of which node is missing.
- You will have to re-enter username/password for functions like email, text, pushbullet, MQTT. In some of those cases, re-entering in one of the flows will apply to all and in others you will have to find each flow instance and re-enter in each.
- Importing flows preserves tabs you created previously.
- Some of the graphical elements may be moved around in some tabs, but in my case it wasn’t too many and easily rearranged.
- You may find that some of your re-loaded nodes have been updated relative to your old configuration. In my case the Shelly node had been updated and I had to edit those flows to work with the updated node.
All in all, re-importing your old flows is robust and fairly seamless. I didn’t have anything to lose because my old configuration was dead. But I was super happy to find that the process replicated my pre-crash Node-RED almost exactly. Hope this helps someone.