Consider the following code for rest API node server.
var restify = require('restify');
var server = restify.createServer();
server.get('/echo/:name', function (req, res, next) {
res.send({name: req.params.name});
next();
});
server.listen(8080, function () {
console.log('%s listening at %s', server.name, server.url);
});
Running up that server with node:
$ node echo.js
restify listening at http://0.0.0.0:8080
It shows 0.0.0.0
which is wrong.
Can anyone the me how to console log the exact IP of the server when its turned on?
Thanks
Update: On executing the following code I am getting the below mentioned output, which is again makes difficult, which IP to pick?
rest_server.listen(config.appPort, function () {
var adrs = require('os').networkInterfaces();
console.log(adrs);
console.log('%s listening at %s', rest_server.name, rest_server.url);
});
Output:
{ 'Local Area Connection': [ { address: '192.168.3.60', family: 'IPv4', internal
: false } ],
'Loopback Pseudo-Interface 1':
[ { address: '::1', family: 'IPv6', internal: true },
{ address: '127.0.0.1', family: 'IPv4', internal: true } ],
'isatap.TEST.ORG':
[ { address: 'fe80::5efe:c0a8:33c',
family: 'IPv6',
internal: false } ] }
restify listening at http://0.0.0.0:8080
192.168.3.60
because it's not internal and IPv4. – Phosphorescent