Reputation: 59
I am new to React and to whole MERN concept, by now I created 1 React app and 1 MERN app so now I wanted to take my skill to higher level and challenge myself to creating something complex.
With stack of MERN and deployed to HEROKU, since this is the only thing I know for now.
Now, I had an idea where I would create app where there would be users with main currency coins where they would get 1 coin every day at midnight and they could bid with other players in particulate time for items. And later on they could use that items in some sort of arena. While I spent few days thinking about it I realized few things:
I don't know how to trigger logic that will executed every day at midnight and where to place it? I know that it cant be on React part since every user will then have different items so it must be on express but is it on backend or on heroku? Are there any npm packages that I can use for that? I found something about CRON npm packages but I am not sure is that is what I need? Also I noticed that heroku put your free apps to sleep and I dont know will it wake up app if I use free heroku?
Upvotes: 0
Views: 40
Reputation: 1525
You are looking for something called Cron jobs (Scheduled jobs/tasks), it is not tied to NodeJs, it is a global concept for any backend language in computer science.
In NodeJs there are many libraries which you can use to achieve this, but you should go with OS cron scedulers in linux(google them I am jotting concepts so you can search and learn)
one of the library to use is https://www.npmjs.com/package/node-cron
and deploying part, check this for heroku support on cron jobs https://devcenter.heroku.com/articles/scheduler
Upvotes: 1