Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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.

like image 917
flossfan Avatar asked Nov 30 '11 11:11

flossfan


People also ask

Can I use node for frontend?

A common misconception among developers is that Node. js is a backend framework and is only used for building servers. This isn't true: Node. js can be used both on the frontend and the backend.

How do I access node js server from another computer?

Given that the port is bind to any IP address other than 127.0. 0.1 (localhost), you can access it from any other system. To view your IP addresses, use ipconfig (Windows) or ifconfig (Linux) command. Find out the IP which is in the same network as the "other system" from which you want access.

How could others on a local network access my nodeJS app while it's running on my machine?

Check you have the correct port - and the IP address on the network - not the internet IP. Otherwise, maybe the ports are being blocked by your router. Try using 8080 or 80 to get around this - otherwise re-configure your router.


2 Answers

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.

like image 179
Samyak Bhuta Avatar answered Nov 01 '22 03:11

Samyak Bhuta


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/');
like image 34
Lloyd Avatar answered Nov 01 '22 02:11

Lloyd