# What does node red use for its scheduling on timing intervals?

**URL:** <https://discourse.nodered.org/t/what-does-node-red-use-for-its-scheduling-on-timing-intervals/29815>\
**Category:** General\
**Created:** [9 July 2020 23:41 UTC](https://discourse.nodered.org/t/what-does-node-red-use-for-its-scheduling-on-timing-intervals/29815 "2020-07-09T23:41:54Z")\
**Posts on this page:** 12\
**Page:** 1

<div class="post-metadata">

**Author:** ![Nodi.Rubrum](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/nodi.rubrum/32/107482_2.png) [@Nodi.Rubrum](https://discourse.nodered.org/u/Nodi.Rubrum)\
**Post date:** [9 July 2020 23:41 UTC](https://discourse.nodered.org/t/what-does-node-red-use-for-its-scheduling-on-timing-intervals/29815/1 "2020-07-09T23:41:54Z")

</div>

What does node red use for its scheduling on timing intervals? Does it use cron or its own internal methodology? I have a flow that I would like to run as consistently as possible on multiple systems, such that it runs 12 times per hour, aligned to the top of the hour, then every 5 minutes there after. This is pretty easy to do via cron for various scripting efforts. But to get node red to mimic this behavior? Wondering if anyone has had a similar requirement? Of course the various systems always vary a bit, even if the system clocks are consistently aligned via NTP, chrony, etc. That is ok, just need to get this task as close to synchronized across sysems as good or as is reasonable. I suspect if I implement NTP, chrony, node red will just leverage the system clock like any other application would, for scheduling, right?

---

<div class="post-metadata">

**Author:** ![michaelblight](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/michaelblight/32/445_2.png) [@michaelblight](https://discourse.nodered.org/u/michaelblight)\
**Post date:** [10 July 2020 07:26 UTC](https://discourse.nodered.org/t/what-does-node-red-use-for-its-scheduling-on-timing-intervals/29815/2 "2020-07-10T07:26:17Z")

</div>

Assuming you're talking about the `inject` node, the source code is in [html](https://github.com/node-red/node-red/blob/master/packages/node_modules/%40node-red/nodes/core/common/20-inject.html) and [js](https://github.com/node-red/node-red/blob/master/packages/node_modules/%40node-red/nodes/core/common/20-inject.js).

This shows for simple repeats it is using Javascript's `setInterval`, and for the more complex ones it is using cron.

There is also a `node-red-contrib-cron-plus` node available, if you prefer something that looks more obviously like cron formatting.

---

<div class="post-metadata">

**Author:** ![dceejay](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/dceejay/32/38_2.png) [@dceejay](https://discourse.nodered.org/u/dceejay)\
**Post date:** [10 July 2020 08:20 UTC](https://discourse.nodered.org/t/what-does-node-red-use-for-its-scheduling-on-timing-intervals/29815/3 "2020-07-10T08:20:33Z")

</div>

as per above - the inject node's 'interval between times' and 'at a specific time' option both use cron.  
 ![image](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/3X/7/1/719f803c140682063d43daed6d76276d9dc3f704.png)

---

<div class="post-metadata">

**Author:** ![knolleary](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/knolleary/32/3_2.png) [@knolleary](https://discourse.nodered.org/u/knolleary)\
**Post date:** [10 July 2020 08:24 UTC](https://discourse.nodered.org/t/what-does-node-red-use-for-its-scheduling-on-timing-intervals/29815/4 "2020-07-10T08:24:42Z")

</div>

Just to clarify - yes the Inject node uses the `cron` npm module under the covers. But that does not mean it uses the cron subsystem of the operating system - it just mimics the cron syntax. Deeper under the covers it still comes down to `setInterval`/`setTimeout`.

---

<div class="post-metadata">

**Author:** ![Nodi.Rubrum](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/nodi.rubrum/32/107482_2.png) [@Nodi.Rubrum](https://discourse.nodered.org/u/Nodi.Rubrum)\
**Post date:** [10 July 2020 14:13 UTC](https://discourse.nodered.org/t/what-does-node-red-use-for-its-scheduling-on-timing-intervals/29815/5 "2020-07-10T14:13:33Z")

</div>

Exactly what I was expecting, thinking, thanks. I wrote a simple flow that uses a delay node and sets msg.delay to force the actual message release to be clock (seconds) aligned. So for example, if I wan the interval to be 5 seconds, but the first inject is at 2 seconds on the clock, the delay is 3 seconds. I see messages passed in sync with the clock, .i.e. 0, 5, 10, 15, 20, 25, etc. of the current minute. I will check out the cron plus module, likely it will be simpler to use it.

---

<div class="post-metadata">

**Author:** ![Colin](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/colin/32/17040_2.png) [@Colin](https://discourse.nodered.org/u/Colin)\
**Post date:** [11 July 2020 07:57 UTC](https://discourse.nodered.org/t/what-does-node-red-use-for-its-scheduling-on-timing-intervals/29815/6 "2020-07-11T07:57:56Z")

</div>

> [@Nodi.Rubrum](#):
>
> such that it runs 12 times per hour, aligned to the top of the hour, then every 5 minutes there after.

Isn't 12 times per hour the same as every 5 minutes?  
I believe that if you set an inject node to repeat at Interval between times every 5 minutes and set the time range 00:00 to 00:00 then it will be aligned to the hour. If I understand correctly then that should do exactly what you want.

---

<div class="post-metadata">

**Author:** ![nlecaude](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/nlecaude/32/25_2.png) [@nlecaude](https://discourse.nodered.org/u/nlecaude)\
**Post date:** [11 July 2020 16:44 UTC](https://discourse.nodered.org/t/what-does-node-red-use-for-its-scheduling-on-timing-intervals/29815/7 "2020-07-11T16:44:44Z")

</div>

The node-schedule library works very well too. I like the fact it’s easy to schedule events at a specific date and time.

> **[node-schedule](https://www.npmjs.com/package/node-schedule)**
>
> A cron-like and not-cron-like job scheduler for Node.

---

<div class="post-metadata">

**Author:** ![Nodi.Rubrum](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/nodi.rubrum/32/107482_2.png) [@Nodi.Rubrum](https://discourse.nodered.org/u/Nodi.Rubrum)\
**Post date:** [11 July 2020 23:46 UTC](https://discourse.nodered.org/t/what-does-node-red-use-for-its-scheduling-on-timing-intervals/29815/8 "2020-07-11T23:46:42Z")

</div>

@nieecaude  
I am using the cron-plus, it was very easy to migrate my python scripting scheduling to node red as I am replacing python for node red over time.

---

<div class="post-metadata">

**Author:** ![Nodi.Rubrum](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/nodi.rubrum/32/107482_2.png) [@Nodi.Rubrum](https://discourse.nodered.org/u/Nodi.Rubrum)\
**Post date:** [11 July 2020 23:49 UTC](https://discourse.nodered.org/t/what-does-node-red-use-for-its-scheduling-on-timing-intervals/29815/9 "2020-07-11T23:49:24Z")

</div>

@Colin  
Yes, but the trick was I wanted the schedule to align to the top of the hour, so that all devices basically do the same thing at the same time, regardless of what node red stops or starts. Given the internal/timeout nature of the automated repetitive injections over time the various devices would tend to drift and lose the tight(er) synchronization I was after.

---

<div class="post-metadata">

**Author:** ![Colin](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/colin/32/17040_2.png) [@Colin](https://discourse.nodered.org/u/Colin)\
**Post date:** [12 July 2020 06:13 UTC](https://discourse.nodered.org/t/what-does-node-red-use-for-its-scheduling-on-timing-intervals/29815/10 "2020-07-12T06:13:16Z")

</div>

> [@Nodi.Rubrum](#):
>
> I wanted the schedule to align to the top of the hour,

An inject node configured as stated does do that. Check the help text for the node.

---

<div class="post-metadata">

**Author:** ![Steve-Mcl](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/steve-mcl/32/4826_2.png) [@Steve-Mcl](https://discourse.nodered.org/u/Steve-Mcl)\
**Post date:** [12 July 2020 07:11 UTC](https://discourse.nodered.org/t/what-does-node-red-use-for-its-scheduling-on-timing-intervals/29815/11 "2020-07-12T07:11:39Z")

</div>

> [@nlecaude](#):
>
> node-schedule library works very well too. I like the fact it’s easy to schedule events at a specific date and time

That is a feature of `node-red-contrib-cron-plus` node. As well as extended Cron expressions and solar times.

---

<div class="post-metadata">

**Author:** ![system](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/1X/d073cd938eafa2e558d7c2cd59003b3ef4963033.png) [@system](https://discourse.nodered.org/u/system)\
**Post date:** [10 September 2020 07:11 UTC](https://discourse.nodered.org/t/what-does-node-red-use-for-its-scheduling-on-timing-intervals/29815/12 "2020-09-10T07:11:39Z")

</div>

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