Node: Sending a request once, but getting two outputs?

const http = require('http')
const server = http.createServer((req, res) => {
    res.setHeader('Content-Type', 'text/plain')
    console.log('Incoming')
    res.write("Hello world, request granted!")
    res.end()
})

server.listen(3000, 'localhost', () => {
    console.log("Listening for requests on port 3000")
})

Whenever I start the server, it says “Listening for requests on port 3000”, thats correct. But when I open the localhost:3000 on Chrome, it puts out “Incoming” TWO TIMES. Why two times? 😀 I don’t get it.

Answer

By default all the browsers try to fetch favicon.png from every site. That’s why you see two request sent to your server.

If you send a request with postman or curl you will see only one request.

Tip: Open the network tab on your browser console and you’ll see a request for the favicon.