Hello everyone,
I have embedded nodered. I’m working with the runtime-api.
I can launch the runtime and a flow and I'm able to find and send messages to a flow.
I want to send a message to node A and listen to what is coming to node B.
I tried to use node.on("input", (msg) => {}) but with no luck maybe I misunderstood something.
my code:
let http = require('http');
let express = require("express");
let RED = require("node-red");
// Create a server
let server = http.createServer(express());
// Create the settings object - see default settings.js file for other options
let settings = {
httpAdminRoot:"/red",
httpNodeRoot: "/api",
userDir:".node-red/",
functionGlobalContext: { }, // enables global context
// logging:"off"
};
// Initialise the runtime with a server and settings
RED.init(server,settings);
let flows=[{"id":"84378caad4a2edd5","type":"tab","label":"Flow 2","disabled":false,"info":"","env":[]},{"id":"a8b383355363e036","type":"inject","z":"84378caad4a2edd5","name":"entry","props":[{"p":"payload"},{"p":"topic","vt":"str"}],"repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"","payload":"123","payloadType":"str","x":430,"y":80,"wires":[["25cef7ec4e5ffb25"]]},{"id":"25cef7ec4e5ffb25","type":"debug","z":"84378caad4a2edd5","name":"debug","active":true,"tosidebar":true,"console":true,"tostatus":false,"complete":"true","targetType":"full","statusVal":"","statusType":"auto","x":700,"y":100,"wires":[]}]
RED.start().then( async () => {
await RED.runtime.flows.setFlows({flows: {flows}})
let {flows: nodeObjects} = await RED.runtime.flows.getFlows({user:'admin'});
let inputNodeObject = nodeObjects.find((f) => (f.name == 'entry'))
let outputNodeObject = nodeObjects.find((f) => (f.name == 'debug'))
await RED.runtime._.nodes.load()
let inputNode = (await RED.runtime._.nodes.getNode(inputNodeObject.id));
let outputNode = (await RED.runtime._.nodes.getNode(outputNodeObject.id));
console.log(outputNode);
inputNode.send({payload: "world hello"});
outputNode.on("input", (msg) => {
console.info(`-----------------------------------`);
console.info(`msg:`);
console.info(msg);
});
})