When creating scheduled events in JavaScript, we use setTimeout() for events that are triggered once and setInterval() for the recurring ones.

Later.js, a stadalone JavaScript library, offers an advanced usage for triggering recurring events and can easily replace both methods for many projects.

Later.js

It has a chainable API which allows us to set complex schedules like:

later.parse.recur() .every(2).hour().first().dayOfMonth() .and() .on(8,20).hour().last().dayOfMonth() .except() .on(12).month();

which would normally take tons of if..else statements.

Also, the library accepts cron expressions or user friendly schedules (like “every 10 seconds”).

P.S. It works both in the browser and Nodejs.

WebResourcesDepot Feed