Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to run server-side scripts in NextJs?

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.

like image 678
Chris Tsironis Avatar asked Dec 12 '25 05:12

Chris Tsironis


1 Answers

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 pm2logic here as well.

like image 197
Sohail Haider Avatar answered Dec 13 '25 19:12

Sohail Haider



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!