Can't access node.js script from web browser - node.js

I installed node.js and socket.io in my CentOS 6.4 server. It is running parallel with Apache, with Apache as main server (port 80)
I wrote a simple Hello world script to test node.js installation:
var http = require('http');
http.createServer(function (request, response) {
response.writeHead(200, {'Content-Type': 'text/plain'});
response.write('Hello World\n');
response.end();
}).listen(8088);
console.log('Server started');
If I run it in command line I get 'Server started'. But when I tryh to access it via web browser, typing http://xxx.xxx.xxx.xxx:8088 it never loads. I've tried to use many other port numbers with no success. I have to ips in my server, but neither of them work, nor my domain addres under those ips.
How could I fix it?
EDIT: node,js is installed in another server, and I'm trying to access it via webbrowser from outside this server.
Thanks!

i think you need to open port 8088 by firewall on server.
see man iptables

Related

My NodeJS server is not working in remove server

When I run my NodeJS server in remote server with script "next" for example, it compiles successful and get "Running in localhost:3000" but when I try to enter to ip:3000 didn't get response from server.
What I should do?
Ubuntu server.
The server respond correctly without :3000
Have you tried to open the ports on your server for port 3000? :)
I'm on Ubuntu so this may be different on your system, but i think this should work for you.
ufw allow 3000
If you want to access remotely you cannot listen your server using localhost
Try to listen server in 0.0.0.0
var http = require('http');
http.createServer(function (req, res) {
res.writeHead(200, {'Content-Type': 'text/plain'});
res.end('Hello World\n');
}).listen(3000, "0.0.0.0");
Debugging this might follow a path on these lines:
Verify the server is actually running on that machine. Try to connect to it locally from another shell on that that remote/server machine (use curl if the machine is headless). If it's not running locally, you clearly won't be able to connect remotely.
Assuming the service is actually running, determine if you have the right IP address for the remote machine. Running something like ifconfig (ipconfig on windows I think?) will tell you this.
Determine if you can reach the machine at all over the network. You might try to send it a ping, or connect to another service you know it's offering. If you can't reach it, is it running a firewall that's preventing you or is there address translation going on somewhere?

Running a node.js server on my VPS on port 3000 and the connection times out

In hostgator I have a VPS running centOS. I installed NodeJS and screen.
I added the following code to a file named index.js:
//1
var http = require('http');
//2
http.createServer(function (req, res) {
res.writeHead(200, {'Content-Type': 'text/html'});
res.end('<html><body><h1>Hello World</h1></body></html>');
}).listen(3000);
console.log('Server running on port 3000.');
On 'screen:1' I run the following command:
node index.js
It gives me the console output stating 'Server running on port 3000.'
I switch to 'screen:0' and run the following command:
curl localhost:3000
and I get the following response:
<html><body><h1>Hello World</h1></body></html>
Yet, when I try my server's IP address (substitute the xxx for a real IP address, cause I'm not disclosing my VPS IP address):
xxx.xxx.xxx.xxx:3000
The page never comes up and eventually it times out.
I've tried various ports (8080, 7000) and to not avail.
Do I need to place the iOS project in a different directory.
Currently I have it in /root/Projects/NodeTutorial2/index.js.
What do I need to do to get a hello world response from my VPS?
If you're getting a response from on the box, but not from other boxes, it's almost certainly a firewall issue. Turning off IPTables or allowing the traffic in on the port in question is one option but an easier / more appropriate option is to simply have your app use port 80 (for HTTP) or 443 (for HTTPS). You can either do that by listening to that port on the app directly, or by having a web server that acts as a reverse-proxy for you (e.g. NGINX or Apache).

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.. ?
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.
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

Can not run node.js app with web client

I wrote and ran a node.js program (eg: hello.js) on my linux server with IP Address 62.x.x.x with basic content:
var http = require('http');
http.createServer(
function(req,res){
res.writeHead(200, {'content-type':'Text plain'});
res.end('Hello ');
}
).listen(8000)
I tried to test it on the server with curl command: curl http: //127.0.0.1:8000
I got the expected result: hello on screen.
But when i tried it on my client machince with a browser client (IE, Firefox,...) http://62.x.x.x:8000 the webbrowser can not load this page and can not return my result.
I don't know what does this error mean?
The problem is that the firewall is stopping the page from loading. You need to configure your firewall to allow outbound traffic on port 8000
Try listeting to your external interface, like
).listen(8000, "62.x.x.x")

Using Cloud9 IDE on an EC2 instance

I've installed Cloud9 IDE on an Amazon EC2 instance and started it with this line:
node bin/cloud9.js
But when I open the IDE address from the browser, there is no response. I've added the port 3000 in the instance security group. I think the problem is I'm trying to load the page from a url such as 'http://ec2-XXX-XXX.compute-1.amazonaws.com:3000/' where the Cloud9 server expects a request url like 'http://127.0.0.1:3000'. I get the page content if I 'wget' 'http://127.0.0.1:3000' from the EC2 instance, so the server is working.
Similar thing happens with node.js 'hello world' example, I get no response if the server 'listens' like this,
http.createServer(function (req, res) {
res.writeHead(200, {'Content-Type': 'text/plain'});
res.end('Hello World\n');
}).listen(1337, "127.0.0.1");
because of the ip parameter, and it works if I change the line to .listen(1337);
What should I change in Cloud9 IDE to make it work through 'http://ec2-XXX-XXX.compute-1.amazonaws.com:3000/'?
You can try running this command and connect to it through localhost:3000. Had the same problem with couchdb.
ssh ec2-XXX-XXX.compute-1.amazonaws.com -L 3000:localhost:3000
The issue is the IP address cloud 9 is bound to by default is the local host address, you should be able to change the value in cloud 9's config to 0.0.0.0 (listen on all addresses)

Resources