Search code examples
node.jsnode-cron

Node js Cron Job execution after 14 days


cron.schedule(5 4 */14 * *){}

Is there any way to make it so it executes continously after 14 days without a reset? enter image description here


Solution

  • In your certain case, the problem is in using crontab.guru and the schedule module itself.

    *    *    *    *    *    *
    ┬    ┬    ┬    ┬    ┬    ┬
    │    │    │    │    │    │
    │    │    │    │    │    └ day of the week (0 - 7) (0 or 7 is Sun)
    │    │    │    │    └───── month (1 - 12)
    │    │    │    └────────── day of month (1 - 31)
    │    │    └─────────────── hour (0 - 23)
    │    └──────────────────── minute (0 - 59)
    └───────────────────────── second (0 - 59, OPTIONAL)
    

    Since the fourth asterisk represents the day of the month (and the sixth is day or week) you can't avoid the reset.

    But you can always find a scheduling module with a day of the year support.

    Later.js (npm) as a part of Bree module could help you with that, I guess.

    Or can write your own wrapper function manually via moment.js or day.js