0

Description:

Hello, following a simple and straight forward tutorial. Everything works fine, but I was just curious as to why I'm getting a double request received when I refresh/access my page?

Part of my code:

function onRequest(request, response){ console.log('request received'); response.writeHead(200, {"Content-Type": "text/plain"}); response.write('Hello world baby'); response.end(); } //creating server http.createServer(onRequest).listen(8888); console.log("server has started"); 

Screenshot:

Image of double console log

12
  • 4
    I bet it's because you're sending two requests. Commented Mar 4, 2015 at 16:03
  • 8
    Probably, your browser is trying to load /favicon.ico from your server. Commented Mar 4, 2015 at 16:04
  • 6
    Use your browser developer console to see actual HTTP requests. Commented Mar 4, 2015 at 16:04
  • 1
    Debug each request with console.log('request received:', request, response); Commented Mar 4, 2015 at 16:06
  • 3
    @gmo it'll be a lot of useless data, something like console.log('request received:', request.url); will be much more useful. Commented Mar 4, 2015 at 16:07

1 Answer 1

2

Your browser is looking for the favicon.ico, then it sends a request for the actual content. Try to console.log both the request and response to get more information.

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.