3

I need a help to create schedule for send a message from node.js application server. i am new to this problem so can anybody please help me how can solve this? i tried "node-schedule" module but it's not persist.

Lokesh G
  • 831
  • 11
  • 19

1 Answers1

4

I may be late to answer this question but it might help others in the future.

in my case, I needed to send a notification on a specific date and time.

I used node-schedule which is a flexible cron-like and not-cron-like job scheduler for Node.js.

start with importing node-schedule

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

then scheduling push notification as below

schedule.scheduleJob(
  `${pushNotification._id}`, //Job name, prefered to be unique 
  scheduledDate, // 2020-05-02T12:52:00.000Z
  async () => {
    await FCM.broadcast({
      topic: 'topic_name',
      title: 'sample title',
      body: 'sample body',
      imageUrl: 'image url sample',
    });
  }
);

and in case you want to cancel the job

schedule.cancelJob('job_id');

and in case you want to reschedule the job

schedule.rescheduleJob('job_id', 'scheduleDate');

hope this would help.

tarek noaman
  • 1,253
  • 1
  • 11
  • 18
  • Hi, can the schedule date just be a date with a time? or do i have to add time as well? Also, in my app, when a user creates an order they are supposed to be reminded with the payment dates. Should i schedule a job when creating an order? – kd12345 Nov 14 '22 at 11:42