How to call function when nextjs application start

Viewed 854

I am trying to add a guardian process for my NextJS application. it will start with the launch of my nextjs application, and then perform some jobs regularly(like backup data).

But I didn't find some "callback" or "eventListener" to let me call my startup function.

I tried to execute the startup function in pages/_app.tsx, but it was called every time when user accessed it, not only once when the nextjs application started.

The following is my expectation:

  • Call only once when the entire nextjs application is started.
  • No need to use a custom backend.(There are already a lot of code accumulated on the default server of Next)
  • Can use the ability provided by Next, such as TypeScript, Babel, export / import, etc.
  • The code in the nextjs application can directly Import related its function and use.

Can anyone provide some inspiration?

0 Answers
Related