How to make my custom node disconnect cleanly

Hello,

I'm working on a custom node that connects to an external websocket. My problem right now is that after I restart node-red the external API gives me a "connection limit exceeded" message.

I think there's a few ways I need to change my code but one I need help with is how can I detect when node-red is closing so that I can make a disconnect() call?

Appreciate the help, thanks,
-Matt

Hi @mdkrieg

you need to handle the 'close' event - this is triggered whenever the node is being stopped. That can be due to a new flow configuration being deployed, or the runtime stopping.

https://nodered.org/docs/creating-nodes/node-js#closing-the-node

Perfect, of course it would be something simple. Thanks!

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