mercredi 23 avril 2014

http - impossible de démarrer un serveur web de base (à l'aide de node.js) sur une instance AWS - Stack Overflow


I have a free AWS instance with node.js installed. I took the following code from the Node Beginner Book (http://www.nodebeginner.org/) -


var http = require("http");

http.createServer(function(request, response) {
response.writeHead(200, {"Content-Type": "text/plain"});
response.write("Hello World");
response.end();
}).listen(8888);

and put it in a file called server.js with the intent to test a basic web server. However, when I run it using node server.js, it simply hangs and doesn't return anything. Can anyone suggest what I might try to fix this problem? Thanks.




It's doing what it's supposed to do. It's running in a loop waiting for connections, not hanging.


If you connect to it with a browser, you will get the desired output (in the browser). There will be no output in console where your running the server (as per your code).




I'm not sure but may be you are not running the node process as deamon or using nohup and hence you feel as though it's hung. Why don't you add a couple of console.log in your code and check?


In amazon AWS instance, you need to configure ports that are accessible. Check the security group tab in your amazon EC2 console.



I have a free AWS instance with node.js installed. I took the following code from the Node Beginner Book (http://www.nodebeginner.org/) -


var http = require("http");

http.createServer(function(request, response) {
response.writeHead(200, {"Content-Type": "text/plain"});
response.write("Hello World");
response.end();
}).listen(8888);

and put it in a file called server.js with the intent to test a basic web server. However, when I run it using node server.js, it simply hangs and doesn't return anything. Can anyone suggest what I might try to fix this problem? Thanks.



It's doing what it's supposed to do. It's running in a loop waiting for connections, not hanging.


If you connect to it with a browser, you will get the desired output (in the browser). There will be no output in console where your running the server (as per your code).



I'm not sure but may be you are not running the node process as deamon or using nohup and hence you feel as though it's hung. Why don't you add a couple of console.log in your code and check?


In amazon AWS instance, you need to configure ports that are accessible. Check the security group tab in your amazon EC2 console.


0 commentaires:

Enregistrer un commentaire