#backend

1 messages · Page 1 of 1 (latest)

past crane
#

NextJS is a full stack framework. Whatever you can do with Express should be possible using Next's Api Routes* (See last paragraph). If you don't mind me asking what is the API you will be requesting?

Something to watch out for is that you don't want every API request to create a new timeout, you only want it once for the entire app. How you deploy your app will determine if this is possible as some platforms such as Vercel have a serverless function execution timeout of 10 seconds.

NodeJS has a setInterval function that you can read about at https://nodejs.org/en/docs/guides/timers-in-node/. This function should set a timeout for 7200000ms which is the equivalent of 2 Hours, and the other API should be called within that function.
Alternatively you could use a package that allows you to set up a cron job.

#

Personally I wouldn't use NextJS for an API like this as it isn't the best for handling background tasks, but it's certainly possible just a bit hacky (e.g. use of a custom server)