Share some config among Function nodes

I’d like to share common config (json) among some Function nodes triggered by separated webhooks within the same workflow.
Is there a way to achieve this, apart from using env vars or external files?

i.e. I’ve tried adding a Set node named config, filled it with some parameters and configured the Function to access them as $node["config"].parameter[0] but it works only if the Set node gets executed.

Hey @davidecavestro! Welcome to the community!

I love the little challenge that you gave us here. The first thing that I thought of was to put it into an environment variable (Oops! Strike 1!). Next, I figures that it could be stored in a file on the host (Dang! Strike 2!). Apparently, I was going to have to get pretty creative to make this work!

So I came up with the following workflow:

Essentially, each of the webhooks fires when a specific event occurs. Next, the corresponding set node creates a webhook key with the webhook number on it. The config set node holds all of your configuration settings. The Switch node then checks the value of the webhook key and sends the output (along with all of the configuration data) out the respective output.

Here is the entire workflow:

Hopefully that helps.

2 Likes

Thank you @Tephlon, your solution just works.

But I must admit I was looking for a way to avoid these kind of switches, just for readability purposes.

IMHO n8n is all about simplicity, and it would be great if someday we had a way to share some config, possibly managed in a similar fashion to credentials (i.e. see NiFi parameters).

Hey @davidecavestro.

So, if I am understanding you correctly, you are looking for something that would be akin to global variables or a global Set node where you could set different parameters which could be referenced outside of the workflow.

I know you referenced this in your initial post, but using a Set node such as this:
image
with the following workflow:

by directly referencing the values set in the Global Config node.

I know that this is not the answer you are looking for but it does provide the required results with the system as it stands today.

The only other way to do this would be for n8n to be rewritten at a base level with another section, as you put it, like the credentials section. If that is the case, my recommendation to you would be to then submit an enhancement request so that the developers could put it into the work and prioritization queue.

1 Like

Thankyou @Tephlon, I’ll try to contribute.
OTOH your last solution remind me an aspect of n8n still obscure to me: is there any guarantee that the Crypt node gets executed after Global Config one? If so, is that documented somewhere?

Hey @davidecavestro,

Unfortunately, not that I am aware of. In fact, without knowing a lot more detail about exactly the order that nodes are executed when the workflow is split like this, my understanding is the they are actually executed approximately at the same time since they will receive the signal to execute at the same time. So, thinking that through, it would probably be worth putting in a “pause” function node for a second or two between the Start and the Crypt node.

By engaging others in the community, you already have and it is a great start!