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.
Asked
Active
Viewed 4,636 times
3
-
you can also use setTimeout with ease, if there are not too many notifications – Naeem Shaikh Feb 12 '15 at 13:55
-
Have you found a solution to your problem yet @Loki Chandu? – thadeuszlay Jul 31 '15 at 18:39
-
i got it i'm using scheduler npm module with db – Lokesh G Aug 01 '15 at 07:24
-
Definately, node-schedule is the best for node.js projects – bmnepali Feb 15 '16 at 09:30
-
@tareknoaman use below npm module for scheduling task and firebase for push notificatin. https://www.npmjs.com/package/node-schedule – Lokesh G Mar 17 '20 at 08:38
1 Answers
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