Assuming you have the basic NestJS setup:
async function bootstrap() {
const app = await NestFactory.create(AppModule);
app.enableCors(corsOptions);
app.useGlobalPipes(
new ValidationPipe({
validateCustomDecorators: true,
transform: true,
whitelist: true,
exceptionFactory: exceptionFactory,
}),
);
app.useGlobalFilters(new CustomExceptionsFilter());
const port = parseInt(process.env.PORT);
await app.listen(port);
}
Can I access the app
variable created with NestFactory from a service in a different module?
@Injectable()
export class TestService {
constructor(
...
) {}
async useApp(): Promise<any> {
const app = ... // use Injected app instance created from AppModule
}
I've tried importing AppModule and creating a NestFactory again, but it just resolves into redundancies.