Reputation: 41
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.
Upvotes: 3
Views: 3171
Reputation: 176
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.
Upvotes: 1