简体   繁体   English

Node.JS-页面持续运行

[英]Node.JS - Page keeps on running

So I download Windows binaries from node's site and installed on my Windows 7 machine which is installed fine, when I do: 所以我从节点的站点下载Windows二进制文件,然后将其安装在安装良好的Windows 7计算机上:

node --version

It correctly displays its version: v0.6.7 它正确显示其版本: v0.6.7

Here is the hello world program: 这是你好世界程序:

// app.js
var http = require('http');

http.createServer(function (req, res) {
  res.writeHead(200, {'Content-Type': 'text/plain'});
  res.end('Hello World\n');
}).listen(8000, "127.0.0.1");

console.log('Server running at http://127.0.0.1:8000/');

And when I do: 当我这样做时:

node app.js

I get the response fine: 我得到的答复很好:

Server running at http://127.0.0.1:8000/

However, when I browser the URL http://127.0.0.1:8000 , the page keeps on running (on status bar it says waiting for 127.0.0.1... ). 但是,当我浏览URL http://127.0.0.1:8000 ,页面继续运行 (在状态栏上显示waiting for 127.0.0.1... )。

Can anybody help me how to make it to output Hello World ? 有人可以帮助我如何使其输出Hello World吗?

This is what I get with curl: 这是我用curl获得的:

$ curl -vv localhost:8000

* About to connect() to localhost port 8000 (#0)
*   Trying ::1... Connection refused
*   Trying 127.0.0.1... connected
* Connected to localhost (127.0.0.1) port 8000 (#0)
> GET / HTTP/1.1
> User-Agent: curl/7.21.4 (universal-apple-darwin11.0) libcurl/7.21.4 OpenSSL/0.9.8r zlib/1.2.5
> Host: localhost:8000
> Accept: */*
> 
< HTTP/1.1 200 OK
< Content-Type: text/plain
< Connection: keep-alive
< Transfer-Encoding: chunked
< 
Hello World
* Connection #0 to host localhost left intact
* Closing connection #0

nothing wrong with it. 没有错。 Try updating node to the latest stable version (but I don't see how it can help) and be sure any process except node is owning the tcp port 8000. 尝试将节点更新到最新的稳定版本(但我看不出它如何提供帮助),并确保除节点之外的任何进程都拥有tcp端口8000。

In my mind, this is either one of two things: 在我看来,这是两件事之一:

  1. Node does not recieve the request 节点未收到请求
  2. Node does not respond to the request 节点未响应请求

To test for either, change your code: 要测试其中之一,请更改代码:

// app.js
var http = require('http');

http.createServer(function (req, res) {
  console.log('got a request');
  res.writeHead(200, {'Content-Type': 'text/plain'});
  res.end('Hello World\n');
}).listen(8000, "127.0.0.1");

console.log('Server running at http://127.0.0.1:8000/');

Try again. 再试一次。 If node does not get the request, try changing the port to 80 instead of 8000, I had a funny case with firefox blocking non-conventional ports a couple of weeks ago. 如果节点未收到请求,请尝试将端口更改为80而不是8000,这是一个有趣的情况,两周前,firefox阻止了非常规端口。

Let me know how you go 让我知道你怎样去

Have you checked your Anti Virus or Windows Firewall? 您是否检查了防病毒或Windows防火墙?

Whichever one you use you might want create a temp exception or disable it for a while just to make sure nothing is getting in the way there. 无论您使用哪种方式,您都可能想要创建一个临时异常或将其禁用一会儿,以确保不会出现任何异常。

Try changing your listen address to 0.0.0.0. 尝试将您的监听地址更改为0.0.0.0。 Maybe you're having problems binding to that specific loopback. 也许您在绑定到该特定环回时遇到问题。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM