node.js服务器正在运行但未加载

时间:2013-11-28 22:22:48

标签: windows node.js

我刚刚在运行Win7(64位)的计算机上安装了node.js.

问题是,当我运行一个简单的hello-world应用程序时,它正在运行(由console.log()确认,我将代码推送到OpenShift并且工作正常)但是当我尝试加载页面时localhost:1337它只是继续加载(最终超时)。

我不知道要检查什么,因为防火墙阻塞节点,而且我没有运行任何阻塞端口的东西。

这是服务器代码。

#!/bin/env node
// Include http module.
var http = require("http");
//Get the environment variables we need if on OpenShift
var ipaddr = process.env.OPENSHIFT_NODEJS_IP || "127.0.0.1";
var port = process.env.OPENSHIFT_NODEJS_PORT || 1337;

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

console.log('It works');
console.log('IP : ' + ipaddr + '\nPort : ' + port);

感谢任何帮助,谢谢。

修改

这是命令行输出的屏幕截图。 http://i.stack.imgur.com/GGaLD.png

1 个答案:

答案 0 :(得分:2)

节点服务器正在挂起,因为您需要始终呼叫response.end

我认为在request上收听end事件会导致超时。如果你删除它将工作。