question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Get reliable server url with `NestApplication.url`

See original GitHub issue

Feature 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:// or https:// 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 case nest start --watch should change the port)

Issue Analytics

  • State:closed
  • Created 4 years ago
  • Reactions:2
  • Comments:5 (4 by maintainers)

github_iconTop GitHub Comments

2reactions
kamilmysliwieccommented, Oct 2, 2019

Getter/method will be enough (without the log)

2reactions
jmcdo29commented, Oct 2, 2019

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?

Read more comments on GitHub >

github_iconTop 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 >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found