Setting up a purely Node.js http server on port 80
Posted
by
Luke Burns
on Server Fault
See other posts from Server Fault
or by Luke Burns
Published on 2011-06-08T19:00:03Z
Indexed on
2012/07/11
9:17 UTC
Read the original article
Hit count: 471
I'm using a fresh install of Centos 5.5. I have Node installed and working (I'm just using Node -- no apache, or nginx.), but I cannot figure out how to make a simple server on port 80. Node is running and is listening to port 80. I'm just using the demo app:
var http = require('http');
http.createServer(function (req, res) {
res.writeHead(200, {'Content-Type': 'text/plain'});
res.end('Hello World\n');
}).listen(80, "x.x.x.x");
console.log('Server listening to port 80.');
When I visit my IP, it does not work. I obtained my ipaddress using ifconfig. I've tried different ports. So there must be something I am missing.
What do I need to configure on my server to make this work? I would like to do this without installing apache or nginx.
Luke
Edit-- Ok so, I installed nginx and started it up, to see whether or not it is related to node, and I don't see its welcome page. So it definitely has something to do with the server.
Am I retrieving the IP Address correctly by running: ifconfig then reading the inet addr under eth0?
© Server Fault or respective owner