Sign in
Log inSign up
Tapas Adhikary

13 likes

·

21.9K reads

2 comments

Diptom Saha
Diptom Saha
Oct 31, 2020

Sir, I am building an REST api in node.js.It store a meeting time and 30 before that time it's send a notifications for that particular meeting.How can I trigger this function for a particular time of every meeting.

3
·
·1 reply
Tapas Adhikary
Tapas Adhikary
Author
·Nov 1, 2020

Hello Diptom Saha,

You can use node-cron for creating a cron job if it has to be happening at a particular time of the day, day of the week, and so on.

  let cron = require('node-cron');

In your case, as the meeting time is known, the cron job can be created with the time that is meeting_time - time_offset(30 mins for example).

The cron.schedule method is capable of taking the customizable pattern too.

cron.schedule('* * * * *', () => {
   console.log('running a task every minute');
});

Cron allowed fields are,

┌────────────── second (optional)

│ ┌──────────── minute

│ │ ┌────────── hour

│ │ │ ┌──────── day of month

│ │ │ │ ┌────── month

│ │ │ │ │ ┌──── day of week

│ │ │ │ │ │

│ │ │ │ │ │

So when you schedule the meeting, schedule a cron also accordingly.

Hope it helps.

1
·