Config node close event

As per the docs I understood a config node can ( and should) handle the close event when necessary. Is that correct? Because it seems my handler is not called in my config node and I assume it should at least be called when terminating node red, right?

Your handler should be called both when NR is closed and when you hit deploy. The first parameter is a flag which tells you which event caused the close if I remember rightly. The second parameter I think is the done callback.

1 Like

That's what I thought. Strangely it never gets called..

I would probably go back and check that things are what you think they are and make sure everything is in the right place. I generally find with things like this that I've made a small mistake that I can't see for looking. console statements everywhere I'm afraid until you spot it. Maybe also compare your code against someone elses.

Hi @realjax,
I have used a close event handler on a config node once, and that worked fine. Can you share your (simplified) code?
Bart

Here's the simplified code:

module.exports = function (RED) {

  function myConfigNode(config) {
    RED.nodes.createNode(this, config);
    var node = this;
    node.name = config.name;
  

    node.on("close", function() {
      console.log('im never called');
    });

... some more functions follow here that all work fine...

When I log the config object from another node it even shows this:

myConfigNode {
  id: 'ba31f7f6.ba7708',
  type: 'gateway-config',
  z: '',
  _closeCallbacks: [ [Function] ],
  name: 'my name!',

..etcetera...

So it seems to know there is a callback on the close event?

Found it !

I made a call to a function on a local variable in the close function. There was however a typo in the variable name which results in the close event not being handled ? No error was shown either, prolly gets lost somewhere then..

So the code was

node.on("close", function() {
      node.somVar.someFunc();
    });

where it should have been

node.on("close", function() {
      node.someVar.someFunc();
    });

thanks everyone for being my rubber ducky :slight_smile:

1 Like