node.jsexpresshostname

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?


Solution

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

    request.headers.host
    

    But that relies on an incoming request.

    More at http://nodejs.org/docs/v0.4.12/api/http.html#http.ServerRequest

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