Get reliable server url with `NestApplication.url`
See original GitHub issueFeature Request
Is your feature request related to a problem? Please describe.
As a user I want to reliably get the server URL.
Describe the solution you’d like
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/
What is the motivation / use case for changing the behavior?
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();
Open topics
- How should we determine when the server is running with the
http://
orhttps://
protocol? - [Follow-up] Where should the log message have its place? The options I come up with are:
- In the
nest new
-schematics (as described above) - Underlying in
NestApplication#listen
- Let
nest start
handle the printing of the message (maybe the way to go, in casenest start --watch
should change the port)
- In the
Issue Analytics
- State:
- Created 4 years ago
- Reactions:2
- Comments:5 (4 by maintainers)
Top Results From Across the Web
Get application url from DI with Nest.js - Stack Overflow
In the main.ts we can get the application url with app.getUrl(). Is is possible to get it from a service via DI ?...
Read more >How To Build a Type-Safe URL Shortener in NodeJS with ...
Successfully created project url-shortener; Get started with the following commands: $ cd url-shortener; $ npm run start ...
Read more >How to Build and Deploy a URL Shortener Using TypeScript ...
In this tutorial, you'll learn how to build a basic URL shortener from scratch using TypeScript and Nest. First, you'll create a basic ......
Read more >NestJS - A progressive Node.js framework
A progressive Node.js framework for building efficient, reliable and scalable server-side applications. Documentation Source code. Extensible. Gives you true ...
Read more >Get the right URL for a service when accessing through ...
Hi there, We have setup an HTTP handler and created a service through SICF in order to connect to SAP from an external...
Read more >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Getter/method will be enough (without the log)
I think this is something I can take on. Do you want the log of
listening on
to be a part of thelisten
function, or do you want it to still be up to the dev to add in the log?