flossfan
flossfan

Reputation: 10864

Set up node so it is externally visible?

Newbie question - might be more appropriate for ServerFault, apologies if so.

I'm setting up node on Ubuntu 11.10, following the excellent howtonode instructions on installing Node.

I can get the Hello World page running on 127.0.0.1:8000, but how do I set it up to appear for my server's external IP?

I'm used to configuring Apache - what's the node equivalent of Apache's "Hello World" page?

Thanks for your help.

UPDATE: Maybe what I need is a tutorial on hosting Node. Would be great if anyone could suggest a good one.

Upvotes: 18

Views: 40736

Answers (3)

Ygautomo
Ygautomo

Reputation: 874

You have to ensure that the designated port (8000) is open to reach.

  1. check open port with iptables -L INPUT -v or ufw status verbose to see if that port 8000 is open
  2. update rules to open the port iptables -I INPUT -p tcp -m tcp --dport 8000-j ACCEPT or ufw allow 8000
  3. check again that the rules implemented iptables -L INPUT --line-numbers or ufw status verbose
  4. if still not reachable set host to 0.0.0.0 so it could reach from any ip.
  5. the try from your browser to reach the server IP_ADDRESS_OR_HOST:PORT

Upvotes: 0

Samyak Bhuta
Samyak Bhuta

Reputation: 1254

There is no configuration needed to make your external IP address work with node.js, unless and until you bind it otherwise.

Instead of .listen(PORT, IP_ADDRESS_OR_HOST ); use .listen(PORT);

Then, just use IP_ADDRESS_OR_HOST:PORT to access it.

Upvotes: 21

Lloyd
Lloyd

Reputation: 29668

You can set up Node to listen on any IP/port, check out http://nodejs.org/docs/v0.6.3/api/http.html#server.listen

Or a quick modified example from the link you supplied:

var http = require('http');

http.createServer(function (req, res) {
  res.writeHead(200, {'Content-Type': 'text/plain'});
  res.end('Hello Node.js\n');
}).listen(80, "192.168.1.1");

console.log('Server running at http://192.168.1.1:80/');

Upvotes: 3

Related Questions