# Config node close event

**URL:** <https://discourse.nodered.org/t/config-node-close-event/12823>\
**Category:** Developing Nodes\
**Created:** [2 July 2019 12:53 UTC](https://discourse.nodered.org/t/config-node-close-event/12823 "2019-07-02T12:53:11Z")\
**Posts on this page:** 8\
**Page:** 1

<div class="post-metadata">

**Author:** ![realjax](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/realjax/32/895_2.png) [@realjax](https://discourse.nodered.org/u/realjax)\
**Post date:** [2 July 2019 12:53 UTC](https://discourse.nodered.org/t/config-node-close-event/12823/1 "2019-07-02T12:53:11Z")

</div>

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?

---

<div class="post-metadata">

**Author:** ![TotallyInformation](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/totallyinformation/32/31_2.png) [@TotallyInformation](https://discourse.nodered.org/u/TotallyInformation)\
**Post date:** [2 July 2019 16:15 UTC](https://discourse.nodered.org/t/config-node-close-event/12823/2 "2019-07-02T16:15:55Z")

</div>

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.

---

<div class="post-metadata">

**Author:** ![realjax](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/realjax/32/895_2.png) [@realjax](https://discourse.nodered.org/u/realjax)\
**Post date:** [2 July 2019 17:27 UTC](https://discourse.nodered.org/t/config-node-close-event/12823/3 "2019-07-02T17:27:56Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![TotallyInformation](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/totallyinformation/32/31_2.png) [@TotallyInformation](https://discourse.nodered.org/u/TotallyInformation)\
**Post date:** [2 July 2019 18:53 UTC](https://discourse.nodered.org/t/config-node-close-event/12823/4 "2019-07-02T18:53:55Z")

</div>

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.

---

<div class="post-metadata">

**Author:** ![BartButenaers](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/bartbutenaers/32/10476_2.png) [@BartButenaers](https://discourse.nodered.org/u/BartButenaers)\
**Post date:** [2 July 2019 19:41 UTC](https://discourse.nodered.org/t/config-node-close-event/12823/5 "2019-07-02T19:41:19Z")

</div>

Hi @realjax,  
I have [used](https://github.com/bartbutenaers/node-red-contrib-onvif-nodes/blob/master/onvif_config.js#L139) a close event handler on a config node once, and that worked fine. Can you share your (simplified) code?  
Bart

---

<div class="post-metadata">

**Author:** ![realjax](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/realjax/32/895_2.png) [@realjax](https://discourse.nodered.org/u/realjax)\
**Post date:** [2 July 2019 20:15 UTC](https://discourse.nodered.org/t/config-node-close-event/12823/6 "2019-07-02T20:15:38Z")

</div>

Here's the simplified code:

```auto
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...

```

---

<div class="post-metadata">

**Author:** ![realjax](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/realjax/32/895_2.png) [@realjax](https://discourse.nodered.org/u/realjax)\
**Post date:** [2 July 2019 20:24 UTC](https://discourse.nodered.org/t/config-node-close-event/12823/7 "2019-07-02T20:24:39Z")

</div>

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

```auto
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?

---

<div class="post-metadata">

**Author:** ![realjax](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/realjax/32/895_2.png) [@realjax](https://discourse.nodered.org/u/realjax)\
**Post date:** [2 July 2019 20:35 UTC](https://discourse.nodered.org/t/config-node-close-event/12823/8 "2019-07-02T20:35:34Z")

</div>

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

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

```

where it should have been

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

```

thanks everyone for being my rubber ducky 🙂
