Flow variable initialization

I have several flow variables that need to be initialized at first deploying. I am using the "Setup" tab in a function node for this purpose.
Am I right?
What happens when NodeRed is restarted?

The setup tab of a function node will get run once whenever the node is started. That happens when the runtime is started and when updated flows are deployed.

You'll want to add a check to make sure the flow variables are undefined before setting them to avoid overwriting them when you deploy changes.... unless of course that's what you want to happen.

Yea, and I am adding that check in the "setup" tab. Is that correct?

I have added this in the setup tab of the function:

if (flow.get("enable_ir_osp") == null) flow.set("enable_ir_osp", true);

Am I protected also from NodeRed restarts?

Yes - add a check in your code before you set anything.

I have edited my previous post

I'm sure you could quickly test it and see.

You can also use an inject node configured to fire a startup feeding a change node (or other) to initialise them.

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.