I’m new to cron and actually not sure if node-cron is the right npm package for me.
Basically, I just want to create a scheduled post feature in my app. Where I can set a time to post my content in the future.
So I discovered node-cron and was able to play around with it. I can get it to work, but I noticed this kind of scheduling in node-cron is about setting intervals, and your function is set to repeat again and again. Correct me if I’m wrong.
But let’s say I’d like to console.log("Hello World")
on Feb, 24, 2023 and run it only once. If I set that on the cron string(not sure what you call it), then I guess I would set it like this:
cron.schedule("* * * 24 Feb *", ()=>{
console.log("Hello World")
})
There is no option to specify a year as I read on the documentation, so where I can I specify the year? My code above will run every second on every Feb, 24 in any year right? Don’t mind “the every second run” on my code above, but what I wanted to do is to specify the exact date and year for it to run, within that specific date only.
I’ve read about node-schedule package where you can pass dates as the schedule, but it seems node-schedule only runs when the script is running?