How we can invoke/trigger the Node Red flow programmatically from Node JS app?

Hi there,

We have embedded the Node-Red into existing Node JS with an express framework app & we wanted to make a sync call to the flow programmatically (without HTTP call) from the same app. Is this something possible?

If Not, then what is the right approach to make a sync call to Node-Red flow?

Thanks.

Welcome to the forums @akshay

You might need to explain what you mean by sync call to the flow programmatically
the methods are already provided.

  • HTTP
  • MQTT
  • TCP
  • etc etc

all of which will trigger a process in your flow.

Having the flow call into your host application however, is achievable enough (I think)

Your Node Application :


const Bridge = () => {
    return {
        someMethod: function() {}
    }
}

const settings = {
    ...
    functionGlobalContext: {
        Host: Bridge()
    }
};

...
RED.init(server,settings);
...

Some Function Node in Node RED :

global.get('Host').someMethod()

EDIT
You could use the above approach to pass to the host application a method provided by a function node (to be called by your Host app), but it could get messy really quickly.