user965369
user965369

Reputation: 5733

node - what's wrong with my app?

I've got httpd running on port 80 and I'm trying to bind a node app to port 8080.

Here it is:

var server = require('http').createServer(function(req, res){

    res.writeHead(200, {'Content-Type': 'text/plain'});
    res.end('Hello World\n');
});
server.listen(8080);

Obviously have run it from ssh command line via

node myApp.js

But whenever I type "http://my-domain:8080/" in the browser it just hangs and gives me nothing..

I've tried a range of different ports and listening on hostname 0.0.0.0, all giving the same result.

Have run netstat as comments suggested and results is :

tcp        0      0 0.0.0.0:8080               0.0.0.0:*                   LISTEN      3894/node           

I'm using centOS on nan unmanaged VPS!

EDIT: Looks like its a firewall issue, could someone point me in the right direction as to how to configure the firewalls for a CentOS VPS.. ?

Upvotes: 1

Views: 1341

Answers (2)

royb
royb

Reputation: 713

try to write:

var http = require('http');
http.createServer(function (req, res) {
  res.writeHead(200, {'Content-Type': 'text/plain'});
  res.end('Hello World\n');
}).listen(8080);
console.log('Server running ');

the .listen(8080); is in the same line.

or to run it with localhost:8080/ from the server may he block from outside

Upvotes: 1

Daniel
Daniel

Reputation: 38771

Might be your firewall settings. In the shell prompt on the server, try connecting with curl.

curl -v http://localhost:8080/

If you can access it via the localhost but not via a browser then you most likely have a firewall issue.

If you can access the server via localhost then the next thing to do is to test the server from the outside via IP address. If you can access it via IP address then you have a DNS issue. If you cannot access it via IP address from the outside then you have firewall issue.

Firewall issues are platform specific. We'd need to know the platform to point you in the right direction.

Upvotes: 2

Related Questions