Execute a function at the launch of the app
Answered
Smaller yellow ant posted this in #help-forum
Smaller yellow antOP
I would like to execute a function at the launch of my Next.js 13 app, a bit like a callback, and by "launch" I mean when I execute npm run dev or launch the server once the project in production.
More specifically I would want to connect to my MongoDB database right at the launch of the app.
More specifically I would want to connect to my MongoDB database right at the launch of the app.
Answered by aardani
No cant do, best you can do is set a singleton pattern which dedupes the function call ensuring you only run once per environment
2 Replies
@Smaller yellow ant I would like to execute a function at the launch of my Next.js 13 app, a bit like a callback, and by "launch" I mean when I execute npm run dev or launch the server once the project in production.
More specifically I would want to connect to my MongoDB database right at the launch of the app.
No cant do, best you can do is set a singleton pattern which dedupes the function call ensuring you only run once per environment
Answer
Smaller yellow antOP
That's what I did for now...