I played with node.js and something strange happens when you run this code:
var http = require("http");
var i = 0;
function onRequest(request, response) {
response.writeHead(200, {"Content-Type": "text/plain"});
response.write("You're number " + i++);
response.end();
}
http.createServer(onRequest).listen(8888);
I expect it to behave like a pageview counter, but each time I refresh the browser tab, I get the result of what seems i=i+2instead of a simple increment. Can someone explain this behavior to me?
source
share