When loging the OnRequest function below (found in this tut http://www.nodebeginner.org/)
var http = require("http");
function onRequest(request, response) {
console.log("Request received.");
response.writeHead(200, {"Content-Type": "text/plain"});
response.write("Hello World");
response.end();
}
http.createServer(onRequest).listen(8888);
console.log("Server has started.");
log will print "Request received." twice each time I refresh the webpage only once : this is annoying since it means I can have side effects when making some other processing.
Why doesn't node.js mitigate this like other http servers ?
My question is not WHY I know why, my question is HOW to detect that it is second time and avoid calling a heavy processing twice ?