Reputation: 5396
The following code produces an exception in node.js under windows:
var Socket = require("net").Socket;
socket = new Socket();
socket.connect(80, "localhost");
here's the message:
events.js:2083: Uncaught Error: getHostByName ENOTFOUND
When I remove localhost
, it works fine. What could be causing this?
I tried turning the firewall off, but to no effect.
Upvotes: 6
Views: 5961
Reputation: 966
In my case adding the Microsoft Loopback Adaptor fixed this issue.
From: http://www.groovypost.com/howto/microsoft/install-a-loopback-adapter-in-windows-7/
Upvotes: 4
Reputation: 13677
node.js uses c-ares resolver and ignores system resolver completely. So the advices regarding C:\WINDOWS\system32\drivers\etc\hosts are probably irrelevant.
c-ares library reads certain system config files - e.g. on Windows and Cygwin it reads /etc/resolv.conf. So you should check if it reads /etc/hosts or C:\WINDOWS\system32\drivers\etc\hosts. If it doesn't and doesn't have builtin support for localhost - then you will have to use 127.0.0.1
Upvotes: 9
Reputation: 5007
Option 1: Dont' use windows ;)
Option 2: in C:\WINDOWS\system32\drivers\etc\hosts
add :
127.0.0.1 localhost
Upvotes: -2