Setting environment variable to time in trigger node

Hello, I want to set environment variable to the time in the trigger node and also to set interval at a inject node Is this possible to set env variable to both the nodes?

trigger nodes can have their delay value set with msg.delay.

But I don't get what you want to do.

You could control the time in the trigger node from an environment variable.
But I think it is called context not environment. (Shrug)

I think environment is fixed.

But what do I know. (Shrug)

Thanks..for reply
But What I want is I have a simple flow which is inserting timestamp into database. I want to make this flow to be run at specific interval like for every 10 sec or 20 sec. So, to make the flow dynamic I will set environment variable to 20 sec in the settings.js file and I want to use that variable in my flow as I am using trigger node for repeated cycle.

I have set the option in trigger node as 'resend it every '

Ok, so you get a heap of inject nodes which inject different values (times) for the delays.

They then go into the trigger node setting the delay time. (msg.delay)

This is a BASIC idea of what I think you want.


Change the values in the inject nodes to the values you want. One sets 2 second delay the other sets 6 second delay.

I included the STOP button only to stop the flow when you are thinking.

Thanks for the help.. I have set environment variable to msg.delay in inject node and its working..

For reference, an "environment variable" is something that the operating system controls. When Node-RED starts, its environment is set and therefore changing environment variables while Node-RED is running is unlikely to be effective.

A context variable is something that Node-RED controls. Sometimes you will see global and flow variables mentioned and these are context variables with a wider context!

As Andrew has said, you can use the inject node to kick things off at set times or intervals. If the inject node does not provide sufficient control. There are lots of other scheduling nodes available as well such as BigTimer and CRON+

@Trying_to_learn and @TotallyInformation thanks for the help..

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