Cron is a utility that will run a function on an interval or according to a cron expression.
npm i -D @darkobits/cron
This package's default export is a factory function that accepts an options object of the following shape:
The object returned by Cron has the following shape:
Cron emits the following events:
Emitted when the Cron is started.
Emitted when a task is about to run.
Emitted after a task finishes running. This callback will receive the return value of the task function.
Emitted when the Cron is suspended.
Emitted when the Cron (or a task) encounters an error. This callback will receive the error thrown.
Using a simple interval:
Using a cron expression:
;;// Run at 12:00 on Wednesdays during every third month.;cron.start;
Setting up event handlers: