I've a following very basic code of HTTP server which is listening on port 8000. How to determine the IP address of server, can it be retrieved from the 'server' variable? I am working on an application where I need to automatically send the server Info (ip,port etc..) to redis store.
I'm new to node.js, Thanks for the help
var http = require("http");
var server = http.createServer(function(request, response) {
response.writeHead(200, {"Content-Type": "text/html"});
response.write("Hello!!!");
response.end();
});
server.listen(8000);
console.log("Server is listening....");
Use the following:
server.address()
Which logs something like:
{ address: '0.0.0.0', family: 'IPv4', port: 8080 }
To log the IP of your server to the console, use:
console.log( server.address().address );
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