cannot connect to server from other computer - node.js

I have a server running CentOs 6.3 with the latest version of node installed on it.
when I execute this code
var http = require('http');
var server = http.createServer(function (request, response) {
console.log('c');
response.writeHead(200, {"Content-Type": "text/plain"});
response.end("Hello World\n");
});
server.listen(80,"0.0.0.0",function(){
console.log(this._connectionKey);
});
// Put a friendly message on the terminal
console.log("Server running");
I get the following messages:
Server running
4:0.0.0.0:80
so far so good, that mean the server should be running.
But, when I try to access the site via the ip the host company gave me I get a "not found" message.
I tryend also ommiting the Ip, changing it to 127.0.0.1 and even to the external Ip. I also changed the port to 1337 and gurnisht, it didnt help.
P.S. This code sample is a test to check what is wrong, I have a more complex server using express with the same problem.
Tnx

well I found the problem.
I had my firewall still working.
I simply stopped the iptables
service iptables stop

Related

server side node.js request couldnt connect to host

I try using server side node.js and write a simple -general- javascript code for http request
var sys = require("sys"),
http = require("http");
http.createServer(function(request, response) {
response.sendHeader(200, {"Content-Type": "text/html"});
response.write("Hello World!");
response.close();
}).listen(1337);
sys.puts("Server running 8080");
when i execute on server it's work and give me out put "Server running 8080" string.
But couldnt connect to host when i check on browser.
(i try this http://myserverip:1337)
I open 1337 port but still same
Same thing on Linux. Check your network connectivity. If you are on Amazon, check your security groups. It has be something that is blocking that port.

Grunt server no error, not working

Grunt is not giving me an error, but when I navigate to the ip address, there is nothing there.
I know node works, because I used node to create a barebones server, and it serves at the same port and works just fine.
When I try to run grunt while the barebones server is running, it says that port is taken, so I know it at least thinks it's serving at that port.
When I used the same files on my local machine, it works just fine, and I can navigate to the port and it works. So does the barebones server.
Any clues as to what could be causing this? By the way, I'm using yo to install angular-bootstrap.
For the barebones server, I just do this:
DIR=~/proj2/www
FILE=hello.js
mkdir -p $DIR
cat <<EOF >$DIR/$FILE
var http = require('http');
var server = http.createServer(function (request, response) {
response.writeHead(200, {"Content-Type": "text/html"});
response.end("<html><body>Hello World</body></html>");
});
server.listen(9000);
EOF
// Change this to '0.0.0.0' to access the server from
hostname: 'localhost'
Well, as the code comment says, you just have to change 'localhost' to '0.0.0.0'.
Thanks, me; you've been very helpful!

Can't access node.js script from web browser

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

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

node.js server port not working

So I am creating a simple server test on my Centos 5.x box and I am having troubles getting node.js to respond on my port:
var http = require("http");
http.createServer(function(request, response) {
response.writeHead(200, {"Content-Type": "text/plain"});
response.write("Hello World");
response.end();
}).listen(8888);
This is the standard copy/pasta test. I had it working last night, and it has since stopped working. I am running this out of /home/user/nodejs and do not get any compilation errors. There are no other node processes running either. Any ideas as to what could have happened between then and now? Any known quirky nodejs problems that may be associated with this?
edits:
I have tested various ports
The page simply times out
RHEL / Centos 5.8 / node v0.6.15
Have you tried to close the firewall?
I have disabled the firewall and it is working.

Resources