8

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

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.

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);

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').

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

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

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.

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.

Any help is appreciated!

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.

7
  • 1
    Change the port to 8000 or 8080 and try again. Let me know how this goes. Dec 18, 2011 at 19:41
  • I've tried those and other ports. Dec 19, 2011 at 15:03
  • There has to be something with a firewall, I've installed Node on W7 on a PC and on Windows XP on other 2 PCs and it worked everywhere. Dec 19, 2011 at 15:05
  • @alessioalex - that's what I would think. I even 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. Maybe I'll try a new install. Dec 19, 2011 at 15:24
  • Uninstall and re-install, maybe there was a problem on installing the first time.. Dec 19, 2011 at 15:28

6 Answers 6

8

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

Here is a solution which I have yet to find anywhere:

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

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

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.

4
  • Mine had two entries, both being allowed. Deleted one, still no success :( Oct 30, 2014 at 0:23
  • Try disabling the firewall and check it. Oct 31, 2014 at 0:45
  • @Navin I have the same problem, even I deleted the duplicate entries, but the username password popup is not appearing again. How to make that appear again. Please help. Jun 10, 2015 at 12:16
  • @Navin - Please help. I have tried many options, like reinstalling node js, when I run node app.js for the first time, the pop up appeared, but it is not coming again. Jun 10, 2015 at 12:18
3

I ran into the same problem and after reading through the documentation, I unexpectedly ran into what I believe is the solution. In my instance I was noticing that the incoming requests WERE being delivered to node, but the response was never having its 'end' event triggered. So altering incoming firewall rules in windows did not seem to be related to the problem.

So, http.createServer takes in a single argument - a function which should include a request and response parameter. The request parameter seemed to be where the problem lay. The request parameter is an instance of http.incomingMessage. This class only had like one event type, but it was itself also an implementation of Stream.Readable, which is where I found the 'end' event that wasn't triggered. Really for no other reason that to just test which was the first event not triggered, I just added a listener for another type of event ('readable'), and only added a console.log line to it which made the whole thing work.

So the code looks simply something like this:

var http = require("http");
http.createServer(function (request, response) {
    console.log('request');
    request.on('readable', function(){
        console.log('request readable');
    });
    request.on("end", function () {
        console.log('request end');
        response.writeHead(200, {
            'Content-Type': 'text/plain'
        });
        response.end('Hello HTTP!');
    });
}).listen(8080);

The above code works, whereas the earlier version below without a 'readable' event listener does not ever respond:

var http = require("http");
http.createServer(function (request, response) {
    console.log('request');
    request.on("end", function () {
        console.log('request end');
        response.writeHead(200, {
            'Content-Type': 'text/plain'
        });
        response.end('Hello HTTP!');
    });
}).listen(8080);

I am not sure why this works except for a little clue in the documentation which reads:

In some cases, listening for a 'readable' event will cause some data to be read into the internal buffer from the underlying system, if it hadn't already.

2

I just tried it and it works for me. Make sure you are not blocking node with your firewall.

1
  • 1
    Disabled firewall and it still won't cooperate. Dec 19, 2011 at 15:04
2

I am using Windows 7 32-bit.

What edition of Windows 7 are you using? Eg. Home Premium, Professional, Ultimate?

A thread on the npm github project mentions similar symptoms while installing nodejs modules using npm, and comments seem to narrow it down to being caused by Windows 7 Professional. It being 32/64-bit doesn't seem to matter.

I am having both the problem you describe, as well as the npm installation problem, and am running on Windows 7 Professional 64-bit.

Using XPMode (a workaround mentioned in the npm thread) has allowed me to workaround both of these issues. Although, I suppose this is just a more Windows-y version of your use of Ubuntu in VirtualBox.

Other workarounds tried without success:

  • Make/run a Debug build of v0.6.6
  • Make/run a Debug build of v0.6.5 (actually crashed in startup)
  • Set various Compatability Modes on the installed node.exe
  • Prepackaged Windows installer of v0.6.5
1
  • I'm using Ultimate. Thank you for the tip-off on the issue; it will be interesting to see if it is related. Dec 31, 2011 at 20:44
2
  1. Go to "Control Panel\All Control Panel Items\Windows Firewall\Allowed Programs"
  2. Click Allow Programs
  3. select nodejs from the list.

This fixed all the problems for me

1

I was having the same problem with this code (Http Server example from this link: http://net.tutsplus.com/tutorials/javascript-ajax/node-js-for-beginners/)

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

I tried windows 7 64-bit version, windows XP virtual machine, ubuntu virtual machine ... nothing! It only worked after I commented the "request.on" line. Your example (which doesn't have this line) worked fine for me. I'm using the latest stable build from node.js (v0.10.18 for windows or linux). Hope this helps anyone having trouble with this.

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.