Node.js schedule

To use node-schedule to execute a task every day at a specific time, you can create a schedule rule using the library's syntax. Here's an example that schedules a task to run every day at 2:30 PM:

First, install node-schedule if you haven't already:

npm install node-schedule

Now, you can use the following code:

const schedule = require('node-schedule');

// Schedule a task to run every day at 2:30 PM
const dailyJob = schedule.scheduleJob('30 14 * * *', () => {
  // Your code here
  console.log('Task executed every day at 2:30 PM');
});

In the above code:

'30 14 * * *' is a cron-like syntax specifying the schedule. It means the task will run when the minute is 30 and the hour is 14 (2 PM). The * in the other positions means "any" for the day of the month, month, day of the week, and year.

Adjust the cron expression based on your preferred time. The first part represents the minute (0-59), the second part represents the hour (0-23), and the other parts represent the day of the month, month, day of the week, and year.

This example will execute the specified task every day at 2:30 PM according to the server's time zone. Ensure that your server's time zone is correctly configured if you want to match a specific local time.

Komentar

Postingan populer dari blog ini

Node.js Telegram Bot API send an image with text

Node.js Telegram BOT retrieve data from API

WhatsApp Web login QR code in an HTML page using whatsapp-web.js