Drew
Drew

Reputation: 24959

node.js server not responding

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

Upvotes: 3

Views: 5098

Answers (1)

Joachim Isaksson
Joachim Isaksson

Reputation: 180917

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.

Upvotes: 10

Related Questions