import { Injectable , OnModuleDestroy } from '@nestjs/common' ; import { Subject } from 'rxjs' ; @ Injectable ( ) export class AppService implements OnModuleDestroy { private shutdownListener$ : Subject < void > = new Subject ( ) ; onApplicationShutdown ( signal ) { console . log ( 'SHUTDOWN' ) ; console . log ( signal ) ; this . shutdownListener$ . next ( ) ; } subscribeToShutdown ( shutdownFn ) { this . shutdownListener$ . subscribe ( ( ) => shutdownFn ( ) ) ; } onModuleDestroy ( ) { console . log ( 'Executing OnDestroy Hook' ) ; } getHello ( ) { return 'Hello World!' ; } }