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.

How can I get the server address?

See original GitHub issue

Hi, how can I get the server address?

import app from './app'
const client = supertest(app)

client.get('/api/customers').then(response => {

})

// how do I find out what port supertest is using?

Thanks.

Issue Analytics

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

github_iconTop GitHub Comments

5reactions
daggerokcommented, Dec 17, 2020
const request = require('supertest'); // npm i -ED supertest
const app = require('../app'); // your expressjs app
const { url } = request(app).get('/'); // next, just use url
console.debug(url); // prints: http://127.0.0.1:57516/
3reactions
ericprudcommented, Feb 20, 2021

The Test object returned by request() is also referenced in the Response object. For folks landing here later, here’s a stand-alone callback example using "supertest": "^6.1.3" and "express": "^4.17.1" which demonstrates four ways to get the host:

const Supertest = require('supertest')
const App = require('express')()
const ReqPath = '/hello'
const Body = 'Hello World'
App.get(ReqPath, function (req, res) { res.send(Body) })

const request = Supertest(App).get(ReqPath)
console.log(
  'request.url:', new URL(request.url).port,
  '\nrequest.host:', request.host,
)
request
  .expect('Content-Length', "" + Body.length)
  .expect(200)
  .end((err, resp) => {
    console.log(
      'request.host:', request.host,
      '\nresp.request.url:', new URL(resp.request.url).port,
      '\nresp.request.host:', resp.request.host,
    )
  })
request.url: 45633 
request.host: undefined
request.host: 127.0.0.1:45633 
resp.request.url: 45633 
resp.request.host: 127.0.0.1:45633

Note that request.host is not populated until request has been end()-ed (or awaited as in @t3hmrman’s example).

Read more comments on GitHub >

github_iconTop Results From Across the Web

What Is My Server Address? - Knowledge base - ScalaHosting
The server address is an external IP address that connects your computer to the Internet Service Provider (ISP), enabling access to various ...
Read more >
What is My Server Address? | HostGator Support
Log in to your Customer Portal. · Select Hosting from the left-hand menu. · Locate your hosting package, then click the Manage link....
Read more >
Find your IP address in Windows - Microsoft Support
Select Start > Settings > Network & internet > Ethernet. Under Properties, look for your IP address listed next to IPv4 address.
Read more >
Finding the Host Name, IP Address or Physical Address of ...
First, click on your Start Menu and type cmd in the search box and press enter. A black and white window will open...
Read more >
How do I find my server IP address? - Quora
First, click on your Start Menu and type cmd in the search box and press enter. A black and white window will open...
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