As a user I want to reliably get the server URL.
After app.listen
the application should know all the needed information.
I would expect the following behavior.
const app = await NestFactory.create(AppModule);
await app.listen(3000);
console.log(app.url) // returns http://[::1]:3000/
To further improve the DX of NestJS I would like to see the server URL logged in the console once I boot up the application. I would suggest the log message should be part of the boilerplate when running nest new [NAME]
.
async function bootstrap() {
const app = await NestFactory.create(AppModule);
await app.listen(3000);
console.log(`Server is listening on ${app.url}`);
}
bootstrap();
http://
or https://
protocol?nest new
-schematics (as described above)NestApplication#listen
nest start
handle the printing of the message (maybe the way to go, in case nest start --watch
should change the port)I think NestApplication#url
should similar to Loobpacks implementation:
(FYI: this._address
in the code is Http.Server#address()
provided by the Node HTTP package. See here)
Sounds useful :) PRs are welcome!
I think this is something I can take on. Do you want the log of listening on
to be a part of the listen
function, or do you want it to still be up to the dev to add in the log?
Getter/method will be enough (without the log)
This thread has been automatically locked since there has not been any recent activity after it was closed. Please open a new issue for related bugs.
Most helpful comment
Getter/method will be enough (without the log)