如果我没记错的话,它几天前用于显示“localhost”.我不确定是什么改变了使server.address().address返回双冒号(::)而不是.
我在这里读到它返回一个IPv6地址(::)如果它可用但它在我的电脑上被禁用了.
https://nodejs.org/api/http.html#http_server_listen_port_hostname_backlog_callback
解决方法:
正如文档所说,
Begin accepting connections on the specified port and hostname. 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. A port value of zero will assign a random port.
因此,以下代码将打印在http:// ::: 3456上运行:
var express = require('express');
var app = express();
var server = app.listen(3456, function () {
var host = server.address().address;
var port = server.address().port;
console.log('running at http://' + host + ':' + port)
});
但是,如果添加显式主机名:
var server = app.listen(3456, "127.0.0.1", function () {
它将打印您想要看到的内容:运行于http://127.0.0.1:3456
您也可以使用some IP lib中指出的some IP lib
此致,亚历山大
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 [email protected] 举报,一经查实,本站将立刻删除。