I'm working on this MERN todo application. I want to create tasks and daily tasks. Daily tasks are going to be everyday, or maybe once a week. I have no idea how can I count time till the next day when I have to show the task on the front-end.
The only idea I have is to make 2 different mongoose models: Task, DailyTask and do something... Still, I can't understand how to set timer till the time, when I have to show the task.
What kind of approach do you think I have to use?
CodePudding user response:
A suitable approach may be to use the task scheduler module node-cron
.
npm install node-cron
To use:
const cron = require('node-cron')
//cron.schedule(interval, function);
//Daily task example: execute every day at 5PM
cron.schedule('0 0 17 * * *', yourTask);
//Weekly task example: execute every week on Monday
cron.schedule('* * * * Mon', yourTask);
See https://github.com/node-cron/node-cron for more information
CodePudding user response:
So how exactly do you have something running in the background that will remind the user when the task is due?
Answer: Assuming that this todo app will be on the cloud and used by many users, you can run a cron task to fetch each user's notes and see if the due date has been reached, and then save a notification for the user to see.
Answer to a similar question: https://stackoverflow.com/a/65468824/6535167