DEV Community

Discussion on: Scheduling and Running Recurring Cron Jobs in Node.JS

Collapse
 
davel_x profile image
davel_x

Hello,

  • If you want to test or create cron pattern, I found the website crontab.guru/ really useful.

  • beware if you use pm2 with multiples instances : your cron will be launched multiple times and you don't always want that.
    To circumvent this, just use the env var that pm2 injects int the process.env :

if (
    process.env.NODE_APP_INSTANCE === '0'
  ) {
    // init your cron here...
  }
Enter fullscreen mode Exit fullscreen mode