Javascript Node.JS-页面继续运行
因此,我从node的站点下载Windows二进制文件,并安装在我的Windows 7计算机上,该计算机安装良好,当我执行以下操作时:Javascript Node.JS-页面继续运行,javascript,node.js,Javascript,Node.js,因此,我从node的站点下载Windows二进制文件,并安装在我的Windows 7计算机上,该计算机安装良好,当我执行以下操作时: node --version node app.js 它正确显示其版本:v0.6.7 以下是hello world节目: // app.js var http = require('http'); http.createServer(function (req, res) { res.writeHead(200, {'Content-Type': 'te
node --version
node app.js
它正确显示其版本:v0.6.7
以下是hello world节目:
// 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/');
当我这样做的时候:
node --version
node app.js
我得到的答复很好:
Server running at http://127.0.0.1:8000/
但是,当我浏览URLhttp://127.0.0.1:8000
,页面继续运行(状态栏上写着等待127.0.0.1…)
有谁能帮助我如何将其输出到“Hello World”?这就是我使用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
$curl-vv localhost:8000
*即将连接()到本地主机端口8000(#0)
*正在尝试::1。。。拒绝连接
*正在尝试127.0.0.1。。。有联系的
*已连接到本地主机(127.0.0.1)端口8000(#0)
>GET/HTTP/1.1
>用户代理:curl/7.21.4(universal-apple-darwin11.0)libcurl/7.21.4 OpenSSL/0.9.8r zlib/1.2.5
>主机:localhost:8000
>接受:*/*
>
没什么问题。尝试将node更新到最新的稳定版本(但我看不出它有什么帮助),并确保node之外的任何进程都拥有tcp端口8000。在我看来,这是两件事之一:
// 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/');
再试一次。
如果node没有收到请求,尝试将端口改为80而不是8000,几周前我遇到了一个有趣的例子,firefox阻止了非传统端口
告诉我您的进展情况尝试将您的侦听地址更改为0.0.0.0。可能您绑定到该特定环回时遇到问题。您是否检查了防病毒或Windows防火墙
无论您使用哪一个,您都可能希望创建一个临时异常或禁用它一段时间,以确保没有任何东西阻挡它 在linux中(我也假设在windows中),Node无法绑定到端口时会抛出一个错误。
并确保Node之外的任何进程都拥有tcp端口8000。
我该怎么做?>curl-vv localhost:8080
给出了*即将连接()到本地主机端口8000(#0)*尝试127.0.0.1。。。已连接*已连接到localhost(127.0.0.1)端口8000(#0)>GET/HTTP/1.1>用户代理:curl/7.21.1(i686-pc-mingw32)libcurl/7.21.1 OpenSSL/0.9.8r zlib/1.2.3>主机:localhost:8000>接受://*>
尝试双重检查您的代码是否有误,尝试不同版本的nodejs,使用不同的端口(非常不寻常的事情,如61331),检查是否运行防火墙规则(我不知道在windows下在哪里可以找到此类信息),检查正在运行的软件并关闭可疑的软件。您还可以尝试从shell运行node,粘贴代码,并可能在每个回调上插入一些console.log
语句(如.listen(12345,函数(){console.log(arguments)})
)。我看到的唯一输出是运行在http://127.0.0.1:8000。没有收到请求
。端口80也被wamp占用。我需要一种方法将另一个专用端口分配给工作正常的节点。请尝试443,这是我使用的端口,但请确保尝试http://而不是https://。或者暂时关闭wamp?尝试了所有这些,不幸的是我仍然看到页面继续加载我会尝试使用Fiddler来查看它所说的发生了什么…只更改侦听地址,而不是同时更改这两个地址。