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.

1 Answer 1

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

Sign up to request clarification or add additional context in comments.

3 Comments

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?
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)."
@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.

Your Answer

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

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.