I'm more or less a node newbie and having a bit of difficulty understanding the the asynchronism aspect of the request / response callback for the http.createServer method.
My understanding was that when a new request is made the anonymouse function would run again for the new client.
However in my testing I've found that the blocking process looks like it effects the response for another requesting client.
I say this because the log message "A new client!" only apears after the first request has finished.
var http = require('http');
http.createServer(function(req, res){
console.log("A new client!");
var startTime = new Date().getTime();
while (new Date().getTime() < startTime + 4000);
res.writeHead(200, {"Content-type" : "text/html"});
res.write("done");
res.end();
}).listen("8888");
I am testing on localhost:8888 with multiple tabs in my browser.
console.logis asynchronous, it will only print after the event loop is freed.console.error/console.warnis blocking.