0

I'm trying to write my first node http server. I have got it running on my linux box. If I type the url in the browser. I see the hello world webpage.

 myLinuxHostName:1227/

I'm now trying to connect to this linux node server from my windows machine. If I type my in the browser from my windows machine the same url I get webpage not available. I tried pinging my linux host and that worked fine. What am I doing wrong?

I'm using the simple http server code that is there on nodejs.org homepage.

sublime
  • 4,013
  • 9
  • 53
  • 92

1 Answers1

1

If you are using this example:

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');
console.log('Server running at http://127.0.0.1:1337/');

Then only runs using this exactly ip 127.0.0.1 whats mean localhost and the other VHost not reach that server. You must doing something like this.

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

For more information: http://nodejs.org/api/net.html#net_server_listen_port_host_backlog_callback

Jesús Quintana
  • 1,803
  • 13
  • 18
  • perfect, thanks for the quick answer. So the hostname specified in there is basically not the host that it runs on but host that it allows to connect? – sublime Nov 08 '13 at 00:41
  • They say that in the documentation: "Begin accepting connections on the specified port and host. If the host is omitted, the server will accept connections directed to any IPv4 address (INADDR_ANY)." – Jesús Quintana Nov 08 '13 at 00:44
  • @sublime: no, the hostname specifies the host it runs on, not the host that it is allowed to connect. If you replace `127.0.0.1` with `myLinuxHostname` then it will also work. Your server has many IP addresses. – slebetman Nov 08 '13 at 01:42