Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Node.js - two connections in Chrome and Safari?

I'm trying this basic Javascript code in Node.js:

var count=1;
var net = require('http');
net.createServer(function(req,res){
    res.writeHead(200,{'Content-Type':'text/plain'});
    res.end((count+=1).toString());
}).listen(3000,"127.0.0.1");

Expected result: Each browser hit increments the count output by 1.

Actual result: Firefox increments by 1 (expected)... Safari + Chrome increment by 2

Huh?

like image 264
Lee Benson Avatar asked Feb 25 '23 02:02

Lee Benson


1 Answers

Yes, as the comments suggested, it's favicon.ico.

Next time log req.url before guessing around :)

like image 94
Ivo Wetzel Avatar answered Mar 03 '23 20:03

Ivo Wetzel