O'Reilly logo

Express.js Blueprints by Ben Augarten, Marc Kuo, Eric Lin, Aidha Shaikh, Fabiano Pereira Soriani, Geoffrey Tisserand, Chiqing Zhang, Kan Zhang

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

Periodical tasks with node-cron

Maybe you are familiar with cron (http://en.wikipedia.org/wiki/Cron). It's a Unix-based task scheduling system that makes running tasks easy. One problem with it is that it's linked to your platform, and it's not trivial to turn it on and off from code.

Meet node-cron (https://github.com/ncb000gt/node-cron). It's basically the same task scheduler but it runs directly from your Node application, so as long as it is up, your jobs should run.

Our strategy is simple: Periodically select all meetings that need mailing, call our mailer with each of these meetings, and then mark it as emailed.

Following this app's convention, let's separate concerns into their own folders, starting with src/tasks/index.js, as shown in the ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required