Akhilesh Singh
Akhilesh Singh

Reputation: 1724

Unable to connect on Browser Node JS Application

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

  1. Install the node js From the official site documentation from here.
  2. Check the node version and npm version ? Everything ok, its showing

node - v 4.4.4 npm -v 2.15.1

  1. Create a sample file name Server.js

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/')
  1. Run the file with node command node server.js.

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

Answers (2)

Atul Agrawal
Atul Agrawal

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

Milanzor
Milanzor

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

Related Questions