How to make a cron job with PM2

Milan Mahata picture Milan Mahata · Feb 28, 2017 · Viewed 32.9k times · Source

I want to make a cron job to send mail every 15 minutes taking data from a database table. In node js I can make a cron job but through PM2 I don't understand where to place the code and how it works.

Answer

Robbie picture Robbie · Mar 1, 2017

Use the --cron option:

-c --cron <cron_pattern>

For example:

pm2 start sendMail.js --cron "*/15 * * * *"

Pm2 will now restart the sendMail.js script on the hour, and at 15, 30 and 45 minutes past the hour