Skip to content

Instantly share code, notes, and snippets.

@RiansyahTohamba
Last active May 12, 2023 02:01
Show Gist options
  • Save RiansyahTohamba/8318593af17355b7ed45a42a80ea3617 to your computer and use it in GitHub Desktop.
Save RiansyahTohamba/8318593af17355b7ed45a42a80ea3617 to your computer and use it in GitHub Desktop.
nodejs set reminder by using cron job
Here's an example of a Node.js script that sets a reminder for a certain date using the node-cron package:
// particular date
const cron = require('node-cron');
const reminderDate = new Date("2022-12-31 23:59:00");
const schedule = cron.schedule(reminderDate, () => {
console.log("Reminder: Do something!");
});
You can set the reminderDate to a specific date and time in the future.
In this example, the reminder will be scheduled to execute at the specified date and time in the future, which is December 31st, 2022, at 11:59 PM.
You can also use the cron expression to schedule the reminder for certain date, for example
========
// particular date time
cron.schedule('59 59 23 31 12 *', () => {
console.log('Reminder: Do something!');
});
This will schedule the reminder to run every December 31st, 23:59:59.
Please keep in mind that this is just a basic example, and you can further expand this functionality by adding persistence, user input, or any other necessary features.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment