Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>According <a href="http://nodejs.org/api/os.html#os_os_hostname" rel="noreferrer">to the node.js documentation for the "os" module</a> you need to load the "os" module, which has a <code>hostname()</code> function:</p> <pre><code>var os = require("os"); var hostname = os.hostname(); </code></pre> <p>However, that only is the hostname - without the domain name (the FQDN). There is no easy way to get the FQDN. You could use <a href="http://nodejs.org/api/dns.html" rel="noreferrer">the node.js DNS functions</a> to try to turn the IP address of the server (which you get with <code>os.networkInterfaces()</code>, see doc link above) into a name. The only problem is servers may have different interfaces and names, so you have to make a decision about which one you want.</p> <p>You tried using the <code>window</code> object, but that only exists in the JavaScript runtime environment of browsers. Server side JavaScript doesn't have windows, obviously, so there is no <code>window</code> object. <a href="https://stackoverflow.com/questions/19849136/does-node-js-have-equivalent-to-window-object-in-browser">See this question: "Does node.js have equivalent to window object in browser"</a>.</p> <p>With this information your question is a little strange - in the browser <code>window.location.hostname</code> is the host part of the URL the current page was loaded from. How do you translate that to a server context? The code you run on node.js is from that very server, by definition, so you don't actually need this information. You (may) need it in the browser because that information is variable, especially when you run mashups (JS code from various sources) your code may not know where the page it runs on was loaded from. On the server you always know it's your local filesystem.</p> <p>By the way, you can always use <code>localhost</code> as the hostname :)</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload