I need to repeat a backend task every hour. I've read that node-cron is good for that. But why not just setInterval(). What is the difference?
Asked
Active
Viewed 1,789 times
0
-
You could, however node-cron has built in ways to handle errors and other features. plus, it also runs on a node fork. – Get Off My Lawn Apr 04 '21 at 13:24
-
I think also the difference is that for cron there can be thrown errors, but the process will be continued, but for setInterval it will stop the whole process. Am I wrong ?? – boolfalse Apr 04 '21 at 13:26
2 Answers
2
Using setInterval()
only allows you to set a repetition by a fixed value of milliseconds. nothing else.
With cron-node
you are much more flexible, because you can set your interval with the full variety of time parts. Seconds, minutes, hours and so forth. It's a real scheduler.
0
node-corn internally use Node's setTimeout() function for running jobs or backend tasks. The major advantage of this it is a real scheduler, for example, its .start() and .stop() methods only when you need it, you can also specify the timezone in which the task should run.
on the other, The setTimeout() method calls a function or evaluates an expression after a specified number of milliseconds.

sameer Ahmed
- 537
- 1
- 5
- 15