# Output from custom node

**URL:** <https://discourse.nodered.org/t/output-from-custom-node/90646>\
**Category:** Developing Nodes\
**Tags:** docker\
**Created:** [2 September 2024 14:12 UTC](https://discourse.nodered.org/t/output-from-custom-node/90646 "2024-09-02T14:12:52Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![mr-jaffery](https://avatars.discourse-cdn.com/v4/letter/m/6f9a4e/32.png) [@mr-jaffery](https://discourse.nodered.org/u/mr-jaffery)\
**Post date:** [2 September 2024 14:12 UTC](https://discourse.nodered.org/t/output-from-custom-node/90646/1 "2024-09-02T14:12:52Z")

</div>

I'm sending data from custom node output. In local setup it works perfectly fine but when i deploy this on docker it does not output anything. What could be the reason?

for reference the .js file code

```auto
module.exports = function (RED) {
  function MqttDataFilterInput(config) {
    RED.nodes.createNode(this, config);
    var node = this;
    node.adapterTypes = config.adapterTypes || "";

    var globalContext = this.context().global;

    globalContext.set('adapterTypes', node.adapterTypes);

    msg = {
      payload: {
        adapterTypes: node.adapterTypes,
      },
    };
    node.send(msg);
    node.on("input", function (msg) {});
}
  RED.nodes.registerType("mqtt-data-filter-input", MqttDataFilterInput);
};

```

---

<div class="post-metadata">

**Author:** ![knolleary](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/knolleary/32/3_2.png) [@knolleary](https://discourse.nodered.org/u/knolleary)\
**Post date:** [2 September 2024 14:21 UTC](https://discourse.nodered.org/t/output-from-custom-node/90646/2 "2024-09-02T14:21:28Z")

</div>

This is likely a timing issue.

You are calling `node.send()` within the constructor of the node - that means it will send the message whilst the runtime is still initialising all of the other nodes in the flow; so it is entirely possible whatever this node is connected to hasn't been created yet and the message is dropped.

Try wrapping the `node.send(msg)` in a `setTimeout` to delay it by a short amount to allow the runtime to finish creating the other nodes.

For example:

```auto
setTimeout(() => {
   node.send(msg)
}, 300)

```

---

<div class="post-metadata">

**Author:** ![mr-jaffery](https://avatars.discourse-cdn.com/v4/letter/m/6f9a4e/32.png) [@mr-jaffery](https://discourse.nodered.org/u/mr-jaffery)\
**Post date:** [3 September 2024 06:37 UTC](https://discourse.nodered.org/t/output-from-custom-node/90646/3 "2024-09-03T06:37:53Z")

</div>

Hi, thanks for your reply. I tried this solution, it is now giving the output. But another problem is observed now. If i use the custom node in two different flows, the input values of the first node are over written by the input values in the node of second flow. What could be the reason of this behaviour?

---

<div class="post-metadata">

**Author:** ![Steve-Mcl](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/steve-mcl/32/4826_2.png) [@Steve-Mcl](https://discourse.nodered.org/u/Steve-Mcl)\
**Post date:** [3 September 2024 06:53 UTC](https://discourse.nodered.org/t/output-from-custom-node/90646/4 "2024-09-03T06:53:15Z")

</div>

You are probably modifying an object. Objects are _like_ pointers.

e.g.

![image](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/3X/6/6/66dd679a1c7608422f92d0d64079564a58390dc3.png)  
_Note how modifying `msg2.payload` updates `msg.payload`_

To avoid modifying the original object, clone the object first. Node-RED provides helper functions for this. `newObject = RED.util.cloneMessage(srcObject)`

---

<div class="post-metadata">

**Author:** ![mr-jaffery](https://avatars.discourse-cdn.com/v4/letter/m/6f9a4e/32.png) [@mr-jaffery](https://discourse.nodered.org/u/mr-jaffery)\
**Post date:** [3 September 2024 10:28 UTC](https://discourse.nodered.org/t/output-from-custom-node/90646/5 "2024-09-03T10:28:49Z")

</div>

This worked, thanks Stephen!

---

<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:** [2 November 2024 10:29 UTC](https://discourse.nodered.org/t/output-from-custom-node/90646/6 "2024-11-02T10:29:03Z")

</div>

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