按照标准的 ExpressJs hello word 示例,我得到了大量的 ' : : '。
为什么会这样?
你好词示例:
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);
});
我发现了一个在端口参数后添加“localhost”的提示。当我只看我的电脑时它解决了,但它无法通过网络工作。我应该怎么办?
最佳答案
代码
var server = app.listen(3000, function () {
listen
函数中没有地址参数,Node会绑定(bind)到任意地址,与IPV4的0.0.0.0
地址相关, 对应于 IPV6
中的 ::
.而这个 IPv6
未指定的地址,0:0:0:0:0:0:0:0
,被缩减为 ::
,
运行后netstat -a
TCP [::]:3000 CP-Q10001:0 LISTENING
我们知道 Node 服务器监听地址 ::
端口 3000
。
请参阅 http.listen
here 中使用了哪个 express.js
app.listen = function listen() {
var server = http.createServer(this);
return server.listen.apply(server, arguments);
};
If the hostname is omitted, the server will accept connections on any IPv6 address (::) when IPv6 is available, or any IPv4 address (0.0.0.0) otherwise.
关于javascript - Expressjs 服务器地址主机不返回任何内容,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/32590756/