Following the standard ExpressJs hello word example, i get a host of ' : : '.
Why does this happen?
hello word example:
var server = app.listen(3000, function () {
var host = server.address().address;
var port = server.address().port;
console.log('Example app listening at http://%s:%s', host, port);
});
I found a tip that was add 'localhost' after port parameter. It solved when i was looking just my pc, but it wont work over the network. What should i do?
I tried the example and had the same output for hostname '::', I did the following change as a workaround:
var server = app.listen(3000, 'localhost', function () {
var host = server.address().address;
var port = server.address().port;
console.log('Example app listening at http://%s:%s', host, port);
});
output:
Example app listening at http://127.0.0.1:3000
This will give you the results you are looking for. You should not need to include 'localhost'
var server = app.listen(3000, function () {
var port = server.address().port;
require('dns').lookup(require('os').hostname(), function (err, add, fam) {
debug('Example app listening at http://%s:%s', add, port);
})
});
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