Get hostname of current request in node.js Express


So, I may be missing something simple here, but I can't seem to find a way to get the hostname that a request object I'm sending a response to was requested from.

Is it possible to figure out what hostname the user is currently visiting from node.js?

10/30/2016 9:10:02 AM

Accepted Answer

If you're talking about an HTTP request, you can find the request host in:

But that relies on an incoming request.

More at

If you're looking for machine/native information, try the process object.

10/23/2014 1:57:37 PM

You can use the os Module:

var os = require("os");



  1. if you can work with the IP address -- Machines may have several Network Cards and unless you specify it node will listen on all of them, so you don't know on which NIC the request came in, before it comes in.

  2. Hostname is a DNS matter -- Don't forget that several DNS aliases can point to the same machine.

Licensed under: CC-BY-SA with attribution
Not affiliated with: Stack Overflow