You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
breaking changeNeeds a breaking change or migration notesdiscussionOpen design question, input welcomeenhancementNew feature or improvement (PRs; issues use the Feature type)
This issue is on track and I might have some ideas to support it in a nonbreaking change version with slight behavior-only changes. In the meantime, please consider issue 👍🏼 on main issue if you also want this feature 🙏🏼
It all seems relatively straightforward. The last step is the only tricky one
Convert createNitroApp into an async function that returns Promise<NitroApp>
Change the plugin invocations to catch the return value from the plugin
If the return value is a Promise, call await Promise.all([pluginPromise])
change the export for nitroApp so that it is initialized when the promise is resolved.
This will ensure that the semantics of order and waiting for one plugin to finish before the next runs are retained. I guess I don't understand why this is complicated...
Sadly, it is not that straightforward without behavior changes / overhead because not all nitro presets are compatible with an async entry today but thanks for your feedback dear @robertpatrick.
any update around this regarding the new major version? its seriously very odd that you can not asynchronously initialize the server through plugins - where are you expected to run async DB/redis init etc.?
you can always use top level await in server.ts entrypoint now or inside any plugin or handler (they lazyily init). just be-aware by doing this, server startup will be blocked and you limit runtime portability since sadly till today top level await is not widely supported.
Is there a good way to obtain the NitroApp instance and pass it to an async function though?
I do want to block server startup until my async handler is done. That's the intention. Limited runtime portability is unfortunate, but acceptable tradeoff... but I also need to be able to hook into nitro to add a request hook, which in turn needs access to the already awaited async function (think DB connection, but also applicable to any network connection you want to initialize once and hook into on request).
The only workaround I can think of, with top level await in mind, would be to have two plugins. First one to feed the NitroApp to an object sitting at a 3rd file. Then a second plugin to then get it from that same object, and actually block itself with a top level await. The plugin function of the second plugin would be a no-op or otherwise register hooks with access to any values awaited during the top level await... But that seems super clunky, not to mention error prone (as you're relying on order of plugins).
What if there was a hook for server start (that can be async)? Called once after all plugins are initialized, but before listen (and thus before any invocations of any request hooks or routes). It's certainly backwards compatible, but is it portable?
breaking changeNeeds a breaking change or migration notesdiscussionOpen design question, input welcomeenhancementNew feature or improvement (PRs; issues use the Feature type)
Activity
Harm-Nullix commentedon Feb 7, 2023
ruslankonev commentedon Apr 24, 2023
fabis94 commentedon Sep 27, 2023
pi0 commentedon Sep 27, 2023
This issue is on track and I might have some ideas to support it in a nonbreaking change version with slight behavior-only changes. In the meantime, please consider issue 👍🏼 on main issue if you also want this feature 🙏🏼
robertpatrick commentedon Oct 17, 2023
It all seems relatively straightforward. The last step is the only tricky one
Promise<NitroApp>await Promise.all([pluginPromise])nitroAppso that it is initialized when the promise is resolved.This will ensure that the semantics of order and waiting for one plugin to finish before the next runs are retained. I guess I don't understand why this is complicated...
pi0 commentedon Oct 17, 2023
Sadly, it is not that straightforward without behavior changes / overhead because not all nitro presets are compatible with an async entry today but thanks for your feedback dear @robertpatrick.
ElYaiko commentedon Dec 7, 2025
Still not an update?
I can't await for plugins in order even with prefix 0,1...
fabis94 commentedon Aug 21, 2026
any update around this regarding the new major version? its seriously very odd that you can not asynchronously initialize the server through plugins - where are you expected to run async DB/redis init etc.?
pi0 commentedon Aug 21, 2026
you can always use top level
awaitinserver.tsentrypoint now or inside any plugin or handler (they lazyily init). just be-aware by doing this, server startup will be blocked and you limit runtime portability since sadly till today top level await is not widely supported.boenrobot commentedon Sep 1, 2026
Is there a good way to obtain the NitroApp instance and pass it to an async function though?
I do want to block server startup until my async handler is done. That's the intention. Limited runtime portability is unfortunate, but acceptable tradeoff... but I also need to be able to hook into nitro to add a request hook, which in turn needs access to the already awaited async function (think DB connection, but also applicable to any network connection you want to initialize once and hook into on request).
The only workaround I can think of, with top level await in mind, would be to have two plugins. First one to feed the NitroApp to an object sitting at a 3rd file. Then a second plugin to then get it from that same object, and actually block itself with a top level await. The plugin function of the second plugin would be a no-op or otherwise register hooks with access to any values awaited during the top level await... But that seems super clunky, not to mention error prone (as you're relying on order of plugins).
What if there was a hook for server start (that can be async)? Called once after all plugins are initialized, but before listen (and thus before any invocations of any request hooks or routes). It's certainly backwards compatible, but is it portable?
chore: every upstream workaround links the issue that ends it
chore: every upstream workaround links the issue that ends it
chore: every upstream workaround links the issue that ends it