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.
Related
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 would like to access http://mypublicIP:2888 with Node.js running on mypublicIP and port. The server times out! Does anyone know why this is happening? What can I try to do to identify the underlying problem?
EDIT
I believe if you don't specify the IP address, Node should be reachable from all network interfaces. Node code:
// Load the http module to create an http server.
var http = require('http');
// Configure our HTTP server to respond with Hello World to all requests.
var server = http.createServer(function (request, response) {
response.writeHead(200, {"Content-Type": "text/plain"});
response.end("Hello World\n");
});
server.listen(2888);
// Put a friendly message on the terminal
console.log("Server running somewhere....");
on the apache machine:
check that node is actually listening on port 8000
check that it's reachable from localhost
check that the request appears in apache's access_log
check if anything relevant appears in apache's error_log
these translate to (on Linux):
netstat -tnlpe | grep -w 8000
telnet localhost 8000
tail /var/log/apache/access_log
tail /var/log/apache/error_log
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
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")