You should be able to use the code below to do this. When the script starts, it will print out the next 10 dates the job will run on:
const CronJob = require("cron").CronJob;
const cronExpression ="0 0 1 JAN *";
const cronJob = new CronJob(
cronExpression,
cronFunction
);
function cronFunction() {
console.log("cronFunction: Running....");
// Add whatever you wish here...
}
// Print out the next dates the job will run
const nextDates = cronJob.nextDates(10);
console.log("Next dates the job will run on:", nextDates.map(d => d.format("YYYY-MM-DD HH:mm")));
cronJob.start();
The output should look like so:
Next dates the job will run on: [
'2022-01-01 00:00',
'2023-01-01 00:00',
'2024-01-01 00:00',
'2025-01-01 00:00',
'2026-01-01 00:00',
'2027-01-01 00:00',
'2028-01-01 00:00',
'2029-01-01 00:00',
'2030-01-01 00:00',
'2031-01-01 00:00'
]
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…