listen() doesn't return?
I'm trying to get started with Node, and have hit a hump. When I try to run the below (same example I've seen everywhere) the "starting..." line executes, as well as "created.", but it seems like the script gets stuck on the next line, and never prints "started." (and the server doesn't work, tried via a browser, telnet, curl, etc). Any advice on how to debug?
var http = require("http");
function onRequest(request, response) {
console.log("Request received.");
res开发者_StackOverflow社区ponse.writeHead(200, {"Content-Type": "text/plain"});
response.write("Hello World");
response.end();
}
console.log("starting...");
var s = http.createServer(onRequest);
console.log("created.");
s.listen(8888);
console.log("started.");
Debian GNU/Linux 6.0.1 (squeeze), 2.6.39-x86_64
Compiled node.js 2011.07.19 v0.4.10 (stable) from source.
Thanks!
Actually it looks like listening has some problems with socket access. Try to change port number, turn off the firewall or run node with root access. Maybe it should help; In other way try it with python or smth like that;
Change the port number to 3000 AND run as root. Ensure port 3000 is NOT being used (i.e. use netstat). You should see the "started" message. Otherwise, I can't really help. I'm running Node 0.4.10 on Ubuntu and I copied/pasted your code; it runs perfectly. If it still doesn't work, reinstall Node.
精彩评论