0

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?

enter image description here

AdityaParab
  • 7,024
  • 3
  • 27
  • 40
  • possible duplicate of [nodejs - http.createServer seems to call twice](http://stackoverflow.com/questions/11961902/nodejs-http-createserver-seems-to-call-twice) – Aaron Dufour Aug 26 '14 at 16:31

2 Answers2

6

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.

Brad
  • 159,648
  • 54
  • 349
  • 530
0

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.

Santiago Rebella
  • 2,399
  • 2
  • 22
  • 29