CodePark/ questions / Configuration & lifecycle hooks
START PRACTICINGPRACTICE
Backend question · NestJS › Configuration & lifecycle hooks

Which lifecycle hook runs once all modules have been initialised, but before the app starts listening for connections?

onApplicationBootstrap

onApplicationBootstrap is called after every module has been initialised, before the app listens for connections.

"
onModuleInit" is wrong. It runs earlier, once the host module's dependencies are resolved, so other modules may not be ready yet. "beforeApplicationShutdown" and "onApplicationShutdown" run when the app is shutting down.