Reputation: 71
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?
Upvotes: 0
Views: 3011
Reputation: 597
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.
Upvotes: 1
Reputation:
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.
Upvotes: 2