0

In vanilla Javascript intepreted in the browser, we can get the hostname using:

window.location.hostname

So, how can I get the same with Javascript running in the server, using Node.js/Express.js?

Better, I need to dynamicly generate URLs to serve static files. How is the best way to attach the hostname to the file path of the files in my Express static file server?

Kind Regards.

Marcos Leonel
  • 78
  • 3
  • 10

1 Answers1

0

you can try something like req.hostname from the req object recieved in each request

Taj
  • 1,718
  • 1
  • 12
  • 16
  • I guess it would work if only my front end, in the same domain, is requesting info. But if I have an API the serve information for multiple domains? – Marcos Leonel Sep 30 '18 at 14:52