I am looking for information about the request and application life-cycle for The NestJS framework. Specifically:
What is the order of execution of the following processes in a request, for a route that implements: middleware, pipes, guards, interceptors, and any other potential request process
What is the lifespan of modules and providers in a NestJS application? Do they last for the lifespan of a request, or the application, or something else?
Are there any lifecycle hooks, in addition to OnModuleInit and OnModuleDestroy?
What causes a Modeule to be destroyed (and trigger the OnModuleDestroy event)?
What is the order of execution of the following processes in a request, for a route that implements: middleware, pipes, guards, interceptors, and any other potential request process
The common order is:
What is the lifespan of modules and providers in a NestJS application? Do they last for the lifespan of a request, or the application, or something else?
They do last for the lifespan of the application. Modules are destroyed when a NestApplication or a NestMicroservice is being closed (see close
method from INestApplication
).
Are there any lifecycle hooks, in addition to OnModuleInit and OnModuleDestroy?
No there aren't at the moment.
What causes a Modeule to be destroyed (and trigger the OnModuleDestroy event)?
See my answer to the second point. As you look interested in lifecyle hooks, you might pay some interest to issues #938 and #550
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With