考虑以下用于 REST API 节点服务器的代码。
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);
});
使用节点运行该服务器:
$ node echo.js
restify listening at http://0.0.0.0:8080
它显示了0.0.0.0
哪个是错误的。
任何人都可以在打开服务器时如何控制台记录服务器的确切 IP 吗?
谢谢
更新:在执行以下代码时,我得到了下面提到的输出,这再次变得困难,选择哪个 IP?
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);
});
输出:
{ '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