I'm new to node.js, I tried to use setTimeout to simulate long connections and hope it act asynchronously.
var http = require('http');
http.createServer(function (request, response) {
console.log('New request @ ' + request.url);
(function (response) {
setTimeout(function () {
console.log('Time is up');
response.writeHead(200, {"Content-Type": "text/plain"});
response.end('Hello World\n');
}, 3000);
})(response);
}).listen(8124);
console.log('Server running at http://127.0.0.1:8124/');
But, the code above perform like a synchronous single thread app, which can only handle one request per 3 seconds.
I thought everything in node.js should act asynchronously. So, what's the problem here?