5

Well, this might be a stupid question, but i'm as n00b as i can be, regarding node.

I set up a server, with the code we can find in any node presentation or tutorial...

var http = require('http');

var server = http.createServer(function(req, res){
    console.log('connection from: ' res.socket.remoteAddress);

    res.writeHead(200, ['Content-Type', 'text/plain']);
    res.write('Hello ');
    res.end('World');
});

server.listen('8080');

My question is, why does my server logs my message twice for every request i make from the browser?

Lightness Races in Orbit
  • 378,754
  • 76
  • 643
  • 1,055
André Alçada Padez
  • 10,987
  • 24
  • 67
  • 120

3 Answers3

16

Your browser is requesting an img to use in the upper corner favicon.

Lightness Races in Orbit
  • 378,754
  • 76
  • 643
  • 1,055
megakorre
  • 2,213
  • 16
  • 23
6

As @megakorre says, it's the default browser behaviour in respect of favicons. It's mentioned in The Node Beginner Book, which is well worth checking out. I too am in the node 'n00b' stage and it helped me a lot.

avstrallen
  • 986
  • 9
  • 9
2

I would also recommend trying out Express (http://expressjs.com/). As a beginner, it really helped me get some core concepts together (simple routing like '/users' and '/users/:id') and it gets rid of some annoyances for you like the double favicon.ico request.

Brad Dickason
  • 492
  • 4
  • 10