Node JS return hostname

前端 未结 2 2142
心在旅途
心在旅途 2020-12-14 05:43

I\'m still learning Node JS and javascript and have an app. I have a configuration file where I need to grab the hostname of the server on Ubuntu 12.04

I tried some

2条回答
  •  予麋鹿
    予麋鹿 (楼主)
    2020-12-14 06:09

    You can only get the same host name you would get from window.location.hostname if you're running a server with http.createServer. In that case, the host name is one of the properties of the request object:

    request.headers.host
    

    I'd love to take credit for this answer, but I'm only here because I didn't know the answer. I found the answer posted at this SO answer.

提交回复
热议问题