基本 Node.js 示例不适用于 Windows 7 [英] Basic Node.js examples not working on Windows 7

查看:82
本文介绍了基本 Node.js 示例不适用于 Windows 7的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我从 http://nodejs.org/#download v0.6.6 安装了 node.js.我使用的是 32 位 Windows 7.

I installed node.js from http://nodejs.org/#download, v0.6.6. I am using Windows 7 32-bit.

我在网上浏览了各种教程,并想在这样做的同时进行实验,但我似乎无法让 node.js 正常工作.Node 将运行我的 .js 文件,但来自浏览器的任何请求都会超时.

I've been going through various tuts online, and want to experiment while doing so, but I cannot seem to get node.js working. Node will run my .js file, but any request from the browser times out.

这是一个典型的 Hello World 示例,但不起作用:

Here is a typical Hello World example that does not work:

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

将我的浏览器指向 127.0.0.1:1337 或 localhost:1337 不起作用.来自浏览器的请求超时.我也试过听(1337,'0.0.0.0')和听(1337,'127.0.0.1').

Pointing my browser at 127.0.0.1:1337 or localhost:1337 does not work. The request from the browser times out. I've also tried listen(1337,'0.0.0.0') and listen(1337,'127.0.0.1').

我知道服务器正在运行;如果我 CTRL+C 并停止节点,浏览器会立即返回 ERR_CONNECTION_RESET.

I know the server is running; if I CTRL+C and stop node, the browser immediately comes back with ERR_CONNECTION_RESET.

我也试过在这个 gist 中运行代码,但它不起作用:https://gist.github.com/1339846.我最终得到控制台输出Listening!"然后没有别的.

I also tried running the code in this gist, which will not work: https://gist.github.com/1339846. I end up with the console output "Listening!" and then nothing else.

此外,我尝试了不同的端口,但我的防火墙已通过

Furthermore, I have tried different ports, and my firewall is off via

netsh firewall set opmode mode=disable

我尝试完全禁用防火墙,但服务停止了.如果我使用 netstat -noa 检查连接,我可以看到节点为浏览器打开了一堆连接,所有连接都处于 CLOSE_WAIT 状态.所以看起来连接正在发生,但 node.js 只是不工作.

I tried with firewall totally disabled, and the service stopped. If I check connections using netstat -noa, I can see node has a bunch of connections opened for the browsers, all in state CLOSE_WAIT. So it looks like connections are happening, but node.js just isn't working.

本应由请求发起的回调函数永远不会执行 - 我在各个区域撒了一些 console.log 语句,它们都执行,除了回调中的任何一条.

The callback function that is supposed to be initiated by a request never executes - I sprinkled some console.log statements in various areas, and they all execute except any in the callback.

我卸载了,重新安装,尝试了几个以前的版本,重新启动了我的机器......什么都没有.

I uninstalled, re-installed, tried a couple previous builds, restarted my machine...nothing.

感谢任何帮助!

更新:我几乎要放弃了.我已经尝试了我能想到的所有方法,最终在 VirtualBox 的 Ubuntu 实例中运行 node.js 比抓住稻草更容易.

UPDATE: I have just about given up. I've tried everything I can think of, and it ended up being easier to run node.js in an instance of Ubuntu in VirtualBox than grasp at straws.

推荐答案

!!!!!!我也遇到了同样的问题....

!!!!!! Same problem happened for me....

这是一个我还没有在任何地方找到的解决方案:

查看Windows 高级安全防火墙,看看Evented I/O for V8 JavaScript 是否被阻止或出现两次.

Look in Windows Firewall with Advanced Security and see if Evented I/O for V8 JavaScript is blocked or appears two times.

如果是这样,取消阻止并删除重复的条目.如果你安装/卸载/安装 nodeJs,会有 2 个条目.

If so unblock it and delete the duplicated entry. If you install/uninstall/install nodeJs, there will be 2 entries.

此外,当 node 首次运行时,Window Firewall 对话框会打开,询问您是否要允许 node 具有防火墙访问权限.如果您按否"或直接关闭窗口而不询问,它将创建 Evented I/O for V8 JavaScript 并且它将被阻止.

Also when node first runs the Window Firewall dialog opens asking if you want to allow node to have firewall access. If you press "No" or just close the window without asking, it will create Evented I/O for V8 JavaScript AND IT WILL BE BLOCKED.

这篇关于基本 Node.js 示例不适用于 Windows 7的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆