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.
Related
I am beginner in node.js programming. I did the simple program. I am running this program in localhost 8086.I am using Webstorm to execute this.This program works perfectly last two weeks. Suddenly it shows the error. I cannot able to run this program in localhost. It shows the error event in (port listen 8086). Can anyone solve this issue? Thanks in advance..
var express=require("express");
var app=express();
app.get("/abc",function(request,response)
{
response.send("I got a request");
console.log("I got a request");
});
app.listen(8086,function()
{
console.log("server running at port 8086");
});
Another application is already using that port. Check if you installed / started another software that might use the port 8086.
EARDRINUSE means that the port is already in use.
You had run another server use the same port like 8086 (in your case).
Maye you had run node app in other terminal in WebStorm. Please close it and run it again.
You can check PORT no. is available or not using by
netstat -tulnp | grep <port no>
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 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!
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
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