I have deployed my website, in my website user have to complete 10 orders every day, i want to reset orders at 9am everyday. i am using MERN stack. how to reset orders ? i am thinking of sending put requests that modifies user orders to 0 at 9am everyday.
import schedule from 'node-schedule'
const { currentUser } = useSelector((state) => state.user) //using Redux to fetch current user
schedule.scheduleJob('0 9 * * *', async () => {
try {
await axios.put(`/details/${currentUser._id}`, {
dailyOrders: 0,
})
} catch (err) {
console.log(err)
}
})
I have tried using node-cron but that didn't work well. it will work only if the user is logged in to the account and have opened the site all the time. If he closes site , node cron will not work.
I have deployed my website! and tried using pm2 start myapi