Reputation: 1724
I just Created a sample test file for my new server (hostgater VPN SERVER) to test the node js Application ? I am shocked when I saw its running at the back end from the terminal but when I access from the browser its showing "Unable to Connect" .
I have Centos Server 6.7 final
The Steps I followed
node - v 4.4.4 npm -v 2.15.1
Server.js
var http = require('http');
http.createServer(function (req, res) {
res.writeHead(200, {'Content-Type': 'text/plain'});
res.end('Hello World\n');
}).listen(3000);
console.log('Server running at 3000/')
Its Running Successfully and console the message also but when I start listen the app at the browser xyz.com:3000. Its Showing Unable to connect.
I can't understand what I am missing, Can anyone guide me.
Upvotes: 0
Views: 724
Reputation: 1520
Please add some route in it for browser or add
http.get({
hostname: 'localhost',
port: 80,
path: '/',
agent: false // create a new agent just for this one request
}, (res) => {
res.setHeader();
res.send('Hello World');
res.end();
// Do stuff with response
})
Upvotes: 1
Reputation: 1930
Contact your server hosting provider (Hostgater) and make them forward port 3000 to your server.
Another solution could be using port 80 instead of 3000, as that port is most probably already open and forwarded.
Upvotes: 1