Express.js- 为什么本地主机是“::”

8

有人能告诉我为什么我的服务器地址(主机)是 :: 而不是 localhost 吗?

var express = require('express');
var app = express();

// respond with "hello world" when a GET request is made to the homepage
app.get('/', function(req, res) {
  res.send('hello world');
});

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);
});

这会返回

Example app listening at http://:::3000

当我访问 http://localhost:3000/ 时,它能够正常运行。

1个回答

5

因为在使用IPv6时,::就像在IPv4中的127.0.0.1一样是localhost。


啊哈。Express 中的标准是 IPv6 吗?有没有办法在两者之间切换? - Davetherave2010
https://dev59.com/z10b5IYBdhLWcg3wQPRN - idstam

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接