Younes Mgharfaoui Younes Mgharfaoui - 1 year ago 86
Node.js Question

Running a simple script on a web server using NodeJS

I'm trying to make a simple JS script run on my web server using NodeJS :

var http = require('http');
var server = http.createServer(function(req,res) {
res.end("Hello World!");

console.log('Server running');

Output when I run this on local :

Hello World!

However, when I try to curl onto my web server it timeout.
I don't know if it's important or not but I have apache2 installed on the web server. Any help would be very much appreciated.

Answer Source

You can't access node.js from outside because it is listening on localhost IP i.e You need to configure node.js to listen on so it will be able to accept connections on all the IPs of your machine. Try this:

server.listen(8000, "");

If it still doesn't work and you are using iptables you may have to open port 8000. Try this:

iptables -I INPUT -p tcp --dport 8000 -j ACCEPT
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download