I am learning Node.js and was trying a simple example of setTimeout(). What is supposed to happen is:
"Dog is running." (5 seconds later) "Dog is done."
But when i run the code, the program runs for 5 seconds and prints both statements. I am not sure why this is happening. My code is below:
var http = require('http');
http.createServer(function(request, response) {
response.writeHead(200);
response.write("Dog is running.\n");
setTimeout(function(){
response.write("Dog is done.");
response.end();
}, 5000);
}).listen(8080);
console.log("Server started!!!")