import { INestApplicationContext, Type } from '@nestjs/common'; import { NestFactory } from '@nestjs/core'; import { WorkerModule } from './worker.module'; type ContextFactory = ( module: Type, ) => Promise; export async function bootstrapWorker( createContext: ContextFactory = (module) => NestFactory.createApplicationContext(module), ): Promise { const app = await createContext(WorkerModule); app.enableShutdownHooks(); return app; } if (require.main === module) { void bootstrapWorker(); }