Get hostname of current request in node.js Express

后端 未结 5 1924
礼貌的吻别
礼貌的吻别 2020-11-28 20:32

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.

5条回答
  •  借酒劲吻你
    2020-11-28 21:17

    If you need a fully qualified domain name and have no HTTP request, on Linux, you could use:

    var child_process = require("child_process");
    
    child_process.exec("hostname -f", function(err, stdout, stderr) {
      var hostname = stdout.trim();
    });
    

提交回复
热议问题