Global/Context Variables


I'm somewhat new to NodeRED, but enjoying it very much and already was able to solve a lot of questions from the docs and this forum.


For my production flows in a business context I need global variables, those will change very seldom, maybe once every few months or once a year. They will need to be present at Node-RED startup. I already found information in forum discussions and the documentation. I know that I can add global context variables to the settings.js file.

I think that is somewhat cumbersome and prone to errors. And I think it may be not the best way to tinker with a settings file just to set a few global variables.

Is there a better way to do this?
Can it be considered by the devs to add a settings dialog to the Node-RED UI to set those variables?

Thanks for your help and insights in advance.

So why not have a flow to store the values into global context?

Thanks for your answer.

Are all flows informations available when (other) flows run? Is something like this initialized at start? Can I make sure the flow setting the variables is run first (is there a "run at startup"-Trigger)?

Edit: Just found the answer myself: Trigger a flow whenever Node-RED starts : Node-RED

You will want to change settings.js to store the context data on disk so it will be there over stop/starts of NR.

     	contextStorage: {
			default    : { module: "localfilesystem" },
 			memory     : { module: "memory" }

Yes, I know that. See my opening post. I mentioned that option in it and akeded if a better solution could be possible or implemented instead of manually editing a settings file.

You only edit the settings file once, after that - with my example - the default for context data will be in storage so stopping NR and restarting it, the data will still remain.

Here is a post I wrote quite a while ago about presistant context you might find helpful:

Thanks again! Very helpful.