Simple http server

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?

Upvotes: 6

Views: 2362

Answers (3)

megakorre
megakorre

Reputation: 2223

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

Upvotes: 16

Brad Dickason
Brad Dickason

Reputation: 502

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.

Upvotes: 2

avstrallen
avstrallen

Reputation: 996

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.

Upvotes: 6

Related Questions