# Error while creating my first custom node - "ReferenceError: done is not defined"

**URL:** <https://discourse.nodered.org/t/error-while-creating-my-first-custom-node-referenceerror-done-is-not-defined/79468>\
**Category:** Developing Nodes\
**Created:** [28 June 2023 16:16 UTC](https://discourse.nodered.org/t/error-while-creating-my-first-custom-node-referenceerror-done-is-not-defined/79468 "2023-06-28T16:16:14Z")\
**Posts on this page:** 7\
**Page:** 1

<div class="post-metadata">

**Author:** ![Vrrrum](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/vrrrum/32/60000_2.png) [@Vrrrum](https://discourse.nodered.org/u/Vrrrum)\
**Post date:** [28 June 2023 16:16 UTC](https://discourse.nodered.org/t/error-while-creating-my-first-custom-node-referenceerror-done-is-not-defined/79468/1 "2023-06-28T16:16:15Z")

</div>

Hi! I'm trying to create my first custom node, but I get this weird error: "ReferenceError: done is not defined" when I try to run my custom node. The thing is I don't use "done" method anywhere in the code. The node is supposed to be simple hysteresis controller.  
.js file:

```js
module.exports = function (RED) {
  function HysteresisNode(config) {
    RED.nodes.createNode(this, config);
    let node = this;
    node.on("input", function (msg) {
      const highPlus = msg.payload.high;
      const lowPlus = msg.payload.low;
      const threshold = msg.payload.threshold;
      const current = msg.payload.current;

      if (threshold + highPlus >= current) {
        msg.payload = node.highOutput;
        node.send(msg);
      } else if (threshold - lowPlus <= current) {
        msg.payload = node.lowOutput;
        node.send(msg);
      }
    });
  }

  RED.nodes.registerType("hysteresis", HysteresisNode);
};

```

.html file:

```html
<script type="text/javascript">
  RED.nodes.registerType("hysteresis", {
    label: "hysteresis",
    category: "function",
    color: "#a6bbcf",
    inputs: 1,
    outputs: 1,
    icon: "font-awesome/fa-cogs",
    defaults: {
      highOutput: { value: false },
      lowOutput: { value: false },
      highOutputType: { value: "bool" },
      lowOutputType: { value: "bool" },
    },
    oneditprepare: function () {
      $("#node-input-highOutput").typedInput({
        type: "bool",
        types: ["bool", "num", "str"],
        default: "bool",
        typeField: "#node-input-highOutput-type",
      });

      $("#node-input-lowOutput").typedInput({
        type: "bool",
        types: ["bool", "num", "str"],
        default: "bool",
        typeField: "#node-input-lowOutput-type",
      });
    },
  });
</script>

<script type="text/html" data-template-name="hysteresis">
  <p>Output values:</p>
  <div class="form-row">
    <label for="node-input-highOutput"
      ><i class="fa fa-tag"></i>Upper Threshold</label
    >
    <input type="text" id="node-input-highOutput" />
    <input type="hidden" id="node-input-highOutputType" />
  </div>
  <div class="form-row">
    <label for="node-input-lowOutput"
      ><i class="fa fa-tag"></i>Lower Threshold</label
    >
    <input type="text" id="node-input-lowOutput" />
    <input type="hidden" id="node-input-lowOutputType" />
  </div>
  <div class="form-tips"><b>Tip:</b> This is here to help.v</div>
</script>

```

package.json

```json
{
  "name": "node-red-contrib-easy-hysteresis",
  "version": "1.0.3",
  "description": "",
  "scripts": {
    "test": "echo \"Error: no test specified\" && exit 1"
  },
  "author": "",
  "license": "ISC",
  "node-red": {
    "nodes": {
      "hysteresis": "hysteresis.js"
    }
  }
}

```

---

<div class="post-metadata">

**Author:** ![ralphwetzel](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/ralphwetzel/32/53713_2.png) [@ralphwetzel](https://discourse.nodered.org/u/ralphwetzel)\
**Post date:** [28 June 2023 19:55 UTC](https://discourse.nodered.org/t/error-while-creating-my-first-custom-node-referenceerror-done-is-not-defined/79468/2 "2023-06-28T19:55:11Z")

</div>

> [@Vrrrum](#):
>
> The thing is I don't use "done" method anywhere in the code.

As the [documentation](https://nodered.org/docs/creating-nodes/node-js#receiving-messages) says:

> With Node-RED 1.0, a new style of the listener was introduced to allow the node to notify the runtime when it has finished handling a message. This added two new parameters to the listener function. Some care is needed to ensure the node can still be installed in Node-RED 0.x which does not use this new style of the listener.
> 
> ```auto
> this.on('input', function(msg, send, done) {
> 
> ```

Did you check if the error persists if you use the correct / current interface definition of

```auto
[...].on('input', function(msg, send, done) { ... }

```

---

<div class="post-metadata">

**Author:** ![Vrrrum](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/vrrrum/32/60000_2.png) [@Vrrrum](https://discourse.nodered.org/u/Vrrrum)\
**Post date:** [1 July 2023 18:42 UTC](https://discourse.nodered.org/t/error-while-creating-my-first-custom-node-referenceerror-done-is-not-defined/79468/3 "2023-07-01T18:42:35Z")

</div>

I've changed my code according to documentation, yet, the same error occurs.

`.js:`

```js
module.exports = function (RED) {
  function HysteresisNode(config) {
    RED.nodes.createNode(this, config);
    let node = this;
    node.on("input", function (msg, send, done) {
      const highPlus = msg.payload.high;
      const lowPlus = msg.payload.low;
      const threshold = msg.payload.threshold;
      const current = msg.payload.current;

      send =
        send ||
        function () {
          node.send.apply(node, arguments);
        };

      if (threshold + highPlus >= current) {
        msg.payload = node.highOutput;
        send(msg);
      } else if (threshold - lowPlus <= current) {
        msg.payload = node.lowOutput;
        send(msg);
      }

      if (done) {
        done();
      }
    });
  }

  RED.nodes.registerType("hysteresis", HysteresisNode);
};

```

`ReferenceError: done is not defined`

---

<div class="post-metadata">

**Author:** ![ralphwetzel](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/ralphwetzel/32/53713_2.png) [@ralphwetzel](https://discourse.nodered.org/u/ralphwetzel)\
**Post date:** [4 July 2023 15:04 UTC](https://discourse.nodered.org/t/error-while-creating-my-first-custom-node-referenceerror-done-is-not-defined/79468/4 "2023-07-04T15:04:10Z")

</div>

The code you posted looks fine. Are you sure, this error is coming from your custom node?  
If you share a link to a repository or post the content of both files here, I could try to test your node on my local system - for verification purposes.

---

<div class="post-metadata">

**Author:** ![Vrrrum](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/vrrrum/32/60000_2.png) [@Vrrrum](https://discourse.nodered.org/u/Vrrrum)\
**Post date:** [7 July 2023 14:16 UTC](https://discourse.nodered.org/t/error-while-creating-my-first-custom-node-referenceerror-done-is-not-defined/79468/5 "2023-07-07T14:16:27Z")

</div>

I'm sorry I haven't responded for so long.  
Here's the .tgz archive with all the files (HTML and JSON files haven't been changed since my first post): [https://we.tl/t-YUvS5APLPc](https://we.tl/t-YUvS5APLPc).  
And this is the flow I'm testing my node at:

```json
[
    {
        "id": "5fc79c843f20daa3",
        "type": "function",
        "z": "02ac266ad9de5972",
        "name": "function 15",
        "func": "msg.payload = {\n high: 0.2,\n low: 0.3,\n threshold: 25,\n current: 24.8\n}\nreturn msg;",
        "outputs": 1,
        "noerr": 0,
        "initialize": "",
        "finalize": "",
        "libs": [],
        "x": 450,
        "y": 300,
        "wires": [
            [
                "24f94a71fc033aa1"
            ]
        ]
    },
    {
        "id": "10dc9f46fc794db2",
        "type": "debug",
        "z": "02ac266ad9de5972",
        "name": "debug 3",
        "active": true,
        "tosidebar": true,
        "console": false,
        "tostatus": false,
        "complete": "false",
        "statusVal": "",
        "statusType": "auto",
        "x": 740,
        "y": 300,
        "wires": []
    },
    {
        "id": "b5f837479d3a02c4",
        "type": "inject",
        "z": "02ac266ad9de5972",
        "name": "",
        "props": [
            {
                "p": "payload"
            },
            {
                "p": "topic",
                "vt": "str"
            }
        ],
        "repeat": "",
        "crontab": "",
        "once": false,
        "onceDelay": 0.1,
        "topic": "",
        "payload": "",
        "payloadType": "date",
        "x": 300,
        "y": 300,
        "wires": [
            [
                "5fc79c843f20daa3"
            ]
        ]
    },
    {
        "id": "24f94a71fc033aa1",
        "type": "hysteresis",
        "z": "02ac266ad9de5972",
        "highOutput": "false",
        "lowOutput": "false",
        "highOutputType": "bool",
        "lowOutputType": "bool",
        "x": 600,
        "y": 300,
        "wires": [
            [
                "10dc9f46fc794db2"
            ]
        ]
    }
]

```

---

<div class="post-metadata">

**Author:** ![ralphwetzel](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/ralphwetzel/32/53713_2.png) [@ralphwetzel](https://discourse.nodered.org/u/ralphwetzel)\
**Post date:** [7 July 2023 18:38 UTC](https://discourse.nodered.org/t/error-while-creating-my-first-custom-node-referenceerror-done-is-not-defined/79468/6 "2023-07-07T18:38:00Z")

</div>

Whereas your node (currently) _isn't doing anything useful_, it's not creating the error you see either - on my system:

 ![image](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/3X/5/5/552d43a50f5d8d54a247d43e349ae11670e8b270.png)

To stay fair: The node does what it is told to do. `highOutput` and `lowOutput` are `undefined`. Just follow [this section](https://nodered.org/docs/api/ui/typedInput/#runtime-handling-of-typed-values) in the documentation to manage the TypedInput control correctly.

---

<div class="post-metadata">

**Author:** ![system](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/1X/d073cd938eafa2e558d7c2cd59003b3ef4963033.png) [@system](https://discourse.nodered.org/u/system)\
**Post date:** [5 September 2023 18:38 UTC](https://discourse.nodered.org/t/error-while-creating-my-first-custom-node-referenceerror-done-is-not-defined/79468/7 "2023-09-05T18:38:45Z")

</div>

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