2

I have the following simple http-server setup using node.js:

var http = require('http'); var port = 12311 http.createServer(function (req, res) { console.log("Incomming request from " + req.connection.remoteAddress); res.writeHead(200, { 'Content-Type': 'text/plain' }); res.end("test string"); }).listen(port); console.log("Listening on " + port); 

As you can see, when a request comes in, I log it to the console. Now when I browse to localhost:12311 the console shows that two connections have come in:

"E:\Program Files\nodejs\node.exe" hello-world-server.js Listening on 12311 Incomming request from 127.0.0.1 Incomming request from 127.0.0.1 

Why is this?

5
  • 2
    Might be the request for the icon. Look at the network tab in the developer tools of your browser. Commented Mar 6, 2014 at 8:57
  • 1
    @dystroy Yes! you are right, I tried logging req.url and guess what? It shows a request for favicon.ico. I guess I wast to fast to ask :) Commented Mar 6, 2014 at 8:58
  • 1
    Try logging more of the request object... it will show you the difference between the 2 requests. Commented Mar 6, 2014 at 8:58
  • 1
    You can log the req.url, properly it's the favicon.ico Commented Mar 6, 2014 at 8:58
  • @dystroy you can write it as a formal answer so I can accept Commented Mar 6, 2014 at 8:59

1 Answer 1

4

It's usually the request for the favicon.ico. Even if you don't have one, it's requested as the norm defines a default file path if you don't set the relevant <link rel="shortcut icon"... in the header.

The best ways to find about the requests are :

  • client side, by opening the developer tools and looking at the network tab.
  • server side, by logging req.url
Sign up to request clarification or add additional context in comments.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.