Search code examples
node.jsnode-red

How to reset custom node functionality when deploy button is pressed in node-red?


I have created a custom node red block. It listens mqtt topic. It's working as I expected. But, when I make some changes and deploy the flow, my custom node is still waiting for previous topics. How to reset the node functionality in custom node?

Any help would be appreciable.


Solution

  • You node should register a listener for the close event - this gets called whenever the node is being stopped as part of a deploy.

    this.on('close', function() {
        // tidy up any state
    });
    

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