Get application url from DI with Nest.js

Viewed 1803

In the main.ts we can get the application url with app.getUrl().

Is is possible to get it from a service via DI ?

async function bootstrap() {
    const app = await NestFactory.create(AppModule);
    await app.listen(3000);
    console.log(`Application is running on: ${await app.getUrl()}`);
}
bootstrap();
1 Answers

You can define app variable outside of bootstrap method and export it:

export let app: INestApplication;

async function bootstrap() {
    app = await NestFactory.create(AppModule);
    await app.listen(3000);
    console.log(`Application is running on: ${await app.getUrl()}`);
}
bootstrap();
Related