我正在浏览一些 node.js 教程。我正在使用 OS X 10.6.8。第一个是以下。
var http = require("http");
http.createServer(function (request, response) {
request.on("end", function () {
response.writeHead(200, {
'Content-Type': 'text/plain'
});
response.end('Hello HTTP!');
});
// Listen on the 8080 port.
}).listen(8080);
我似乎根本无法访问端口 8080。我的 localhost 和 127.0.0.1 在我访问它们时工作正常,但使用上面的示例 127.0.0.1:8080/ 和 localhost:8080/ 但说“Safari 无法连接到服务器”。
我假设这个端口是如何关闭的?我确信这是一个常见问题,但搜索并没有多大帮助。
我还应该补充一点,防火墙在首选项中已关闭。
有任何想法吗?