小编use*_*003的帖子

node入门,等待localhost

我是 Node.js 的新手,所以我想我会检查一下并做一个 hello world。我在我的所有三台机器(Win 8、Win 7 和 Mac)上都遇到了同样的问题。起初以为是防火墙问题,但我检查了一下,它在 Mac 和 Windows 8 机器上都关闭了(没有费心检查 win7)。当我从终端运行 Node 时,浏览器会等待 localhost,然后最终超时。我已经在这两天了,似乎无法通过谷歌找到任何解决方案。我错过了什么。?

这是我的代码:

var http = require("http");
console.log("file loaded");

http.createServer(function (request, response) {
   request.on("end", function () {
      response.writeHead(200, {
         'Content-Type': 'text/plain'
      });

      response.end('Hello HTTP!');
   });
}).listen(8080);
Run Code Online (Sandbox Code Playgroud)

javascript http node.js

1
推荐指数
1
解决办法
5090
查看次数

标签 统计

http ×1

javascript ×1

node.js ×1