Newbie question: creating building-blocks that I can call from multiple flows


Have been working with node-red for the past couple of weeks, and have successfully migrated from, extremely happy!

A newbie question:

I sometimes have a set of nodes that combine into a "function" - for example, the input payload is the name of a radio station to stream, and the nodes interpret that into a URL and then send it to the android streamer for streaming.

I call this "function" from multiple flows (some handle HTTP requests, some handle IR signals and some for automation) so I've put a link-in node at the beginning, and then when I need to set a radio station from any flow, I just set the payload and use a link-out node to attach to the radio module.

All's great, but link-out is asynchronous and does not return, so I have no way to do something when the radio stuff is done.

Is there a way to pack a set of nodes into a callable "module" of some sort, and call it synchronously?


1 Like

I am not sure what you need as i am a newbie myself but what i think might help you is this, i found out that you can check the topic that goes into a function and then work with the payload as you wish so i am using it to store some variables inside said function node this is an example of the code i am using

if (msg.topic == "delay") {
if (msg.payload >=1 && msg.payload<120)
return null;

if (msg.topic == "enable") {
context.state = msg.payload;
return null;

so if the topic i get is enable i use the payload to set a boolean variable
if the topic is delay i use it to set a integer variable.

I hope this is of any help to you

Have a look at subflows and see if that does what you want.


This is exactly what I wanted!
Thank you!
I've searched a lot, can't believe I missed it...
Thanks again, Colin.