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
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);
};
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.
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?
You are probably modifying an object. Objects are like pointers.
e.g.
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)