Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

node.js server not responding

Tags:

node.js

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

like image 451
Drew Avatar asked Sep 23 '26 04:09

Drew


1 Answers

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.

like image 119
Joachim Isaksson Avatar answered Sep 24 '26 20:09

Joachim Isaksson



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!