I am using node-cron package for scheduling node-cron jobs. I want to schedule an node-cron job which will run every new month. for example: My node-cron job should run at 1 September 2020 after that it should run at 1 October 2020 and and so on..! Please help me out for the above issue. Thanks in advance.
Asked
Active
Viewed 5,301 times
3 Answers
9
I've tested accepted answer's code and noticed that there is something off.
cron.schedule(* * 1 * *) will make code run every first day of the month, and every hour and every minute. This means if it is first day of month, code will run once every minute.
To correct this issue (and actually run once a month, not multiple times in one day) we change: cron.schedule(* * 1 * *) to: cron.schedule(0 0 1 * *) so code runs every first day, at 00:00.

Dharman
- 30,962
- 25
- 85
- 135

Giovanni Pizzato
- 91
- 1
- 3
3
Following this tutorial I believe you just have to do:
const cron = require("node-cron");
cron.schedule("* * 1 * *", function() {
// Do something
});
where:

Getter Jetter
- 2,033
- 1
- 16
- 37
-
cron.schedule("* * * 1 * *", function() { // Do something }); Missed a * – Ahmad Habib Apr 12 '22 at 08:42
0
cron.schedule("* * * 1 * *", function() { // Do something });
OR
cron.schedule("* * 1 * *", function() { // Do something });
NOTE : remember that the first * of the six * is optional

Reda El Ouahabi
- 81
- 5