Files
nest/integration/repl/src/database/database.module.ts
Dmitry Zhlobo b84c1fe459 fix(core): gracefully shutdown the app when repl exits
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.
2025-05-28 14:59:22 +02:00

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],
};
}
}