mirror of
https://github.com/nestjs/nest.git
synced 2026-02-24 00:02:56 +00:00
The application module we pass to repl may have long-running phases (e.g. database connection polling) and if we don't finish those long-running phases the repl would stuck on exit possibly forever. I encoutered this issue while using MikroORM.forRoot module. The solution is to call `app.close()` when repl exits. Modules should implement graceful shutdown using lifecycle hooks.
21 lines
502 B
TypeScript
21 lines
502 B
TypeScript
import { DynamicModule, Module } from '@nestjs/common';
|
|
import { DatabaseConnection } from './database.connection';
|
|
|
|
@Module({})
|
|
export class DatabaseModule {
|
|
static forRoot(): DynamicModule {
|
|
const connectionProvider = {
|
|
provide: DatabaseConnection,
|
|
useFactory: () => {
|
|
return DatabaseConnection.connect();
|
|
},
|
|
};
|
|
return {
|
|
global: true,
|
|
module: DatabaseModule,
|
|
providers: [connectionProvider],
|
|
exports: [connectionProvider],
|
|
};
|
|
}
|
|
}
|