I have running Node.JS & Express application on localhost (127.0.0.1) and I need to find out the current host (domain) without making requests (for cron job that starts when server is created). The server is created this way
app = express.createServer();
app.listen(PORT);
Now I've found following solution
app.address();
However the host returned by this is 0.0.0.0
, port is returned correct so I guess I need to somehow specify the host during the server start. How can I force it to get the correct host? I've tried
app = express.createServer({host: '127.0.0.1'});
but that doesn't work :(
http://nodejs.org/docs/latest/api/os.html#os.hostname
os.hostname()
Returns the hostname of the operating system.
Looks like it might be what you're looking for.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With