0

I am using Express 4.x. and I'm in a function like:

async function getIndexHTML(req, res) {

}

When I try to log error like this:

console.error(req);

It returns a [Object]

When I try to do this:

console.error(JSON.stringify(req));

It comes with another error

--> starting at object with constructor 'Socket'
1|testprj  |     |     property 'parser' -> object with constructor 'HTTPParser'
1|testprj  |     --- property 'socket' closes the circle
1|testprj  |     at JSON.stringify ()
1|testprj  |     at getIndexHTML (/root/mytest/app.js:114:24)

I just want to know what exact URL the user is typing into the addressbar. What should I do?

AGamePlayer
  • 7,404
  • 19
  • 62
  • 119
  • 1
    Does this answer your question? [How to get the full URL in Express?](https://stackoverflow.com/questions/10183291/how-to-get-the-full-url-in-express) – Omri Attiya Jan 29 '22 at 07:17

1 Answers1

0

You can create the Full-URL from request like this:

const fullURL = `${req.protocol}://${req.hostname}${req.originalUrl}`
Mohammad ZF
  • 113
  • 1
  • 10