3

i am trying this simple demo off of the node.js home page:

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

i have opened the port on amazon ec2 (1337) in its security group.

[root@domU-12-31-38-01-8A-8D servers]# /usr/local/bin/node nodeexample.js
Server running at http://127.0.0.1:1337/

i get nothing back but the typical server is not responding. please help this noob out danke

12
  • ./node --version v0.8.9 Commented Nov 17, 2012 at 15:29
  • How are you trying to send a request off to the server? Commented Nov 17, 2012 at 15:29
  • chrome secure.mathpdq.com:1337 Commented Nov 17, 2012 at 15:30
  • Try 127.0.0.1 or localhost (on the same machine, of course). Commented Nov 17, 2012 at 15:30
  • 1
    @DrewPierce Listen to 0.0.0.0 instead. Commented Nov 17, 2012 at 15:35

1 Answer 1

10

You're listening to 127.0.0.1 which makes node listen only to the loopback interface and only lets it be be reached from localhost itself.

If you listen to 0.0.0.0 instead, you will listen to all the machine's network interfaces and lets you be reachable over the Internet on any public IP the machine is using. This is probably what you want.

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

1 Comment

Up voted because this problem exists beyond the scope of a node app. This is a really important principle to remember!

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.