i am new to NextJs and I'm tryin to make an app that every few hours make some requests to a database to update the data, but i can't figure out how to do it. The only place where i can do it is inside the pages components, but that means that there has to be a request from a client in order to trigger the update script but i want it to be executed continuously when the server starts and every few hours after that.
I think you have two options you can either use vercel's cron method. https://vercel.com/docs/concepts/solutions/cron-jobs
What I'm more comfortable with is, using some setInterval
logic inside my app.ts (app.js)
where its mere a express server starting point. It will keep fetching the data with setInterval
. we might use some pm2
logic here as well.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.