user784637
user784637

Reputation: 16152

node.js script works off command line but not from browser?

I launched and amazon ec2 instance running ubuntu 12.04

I then followed the instructions to install node.js from here http://howtonode.org/how-to-install-nodejs

sudo apt-get install g++ curl libssl-dev apache2-utils
sudo apt-get install git-core

git clone git://github.com/ry/node.git
cd node
./configure
make
sudo make install

I then used the example code to make hello.js

var http = require('http');
http.createServer(function (req, res) {
  res.writeHead(200, {'Content-Type': 'text/plain'});
  res.end('Hello Node.js\n');
}).listen(8124, "127.0.0.1");
console.log('Server running at http://127.0.0.1:8124/');

I then ran hello.js

/var/www$ node hello.js
Server running at http://127.0.0.1:8124/

However, when I try to access this from the url, with http://ec2-***.compute-1.amazonaws.com:8124/ I get an error page from my browser.

Any advice on how to get it to show up in the browser?

EDIT I'm still encountering this problem after changing the above line of code

}).listen(8124, "127.0.0.1");

to this

}).listen(8124);

Upvotes: 0

Views: 990

Answers (2)

Manoj Kumar Singh
Manoj Kumar Singh

Reputation: 29

I also had same issue, Uninstalling skype worked for me, You can also search for some setting which force skype to move to some other port.

Upvotes: 0

Brad
Brad

Reputation: 163528

127.0.0.1 is the loopback address. Only the host can access it. If you want to listen on any available IP, just don't specify that parameter. Otherwise, specify the real IP you want to listen on.

Upvotes: 2

Related Questions