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.
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.
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.
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.
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.
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/');
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With