I am learning Node.js
and I have created this simple http
server.
var http = require('http');
var server = http.createServer(function(req,res){
console.log('request accepted');
res.end();
});
server.listen(3000,function(){
console.log("Server listening on port #3000");
});
It is working fine but when I visit http://localhost:3000/
the console logs request accepted
thing twice. In short, if I'm understanding correctly, the request is received twice.
Is it a correct behavior or am I doing something wrong here?
Your browser makes two HTTP requests. One for the page at /
and the other for /favicon.ico
.
You can prove this by inspecting req.url
.
you can try to put your favicon as a data64 string so you will save that request, anyway some browsers could make that request anyway.