Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

node.js beginner - why does this receive 2 responses?

Tags:

node.js

var http = require("http");

function onRequest(request, response) {
  console.log("Request received.");
  response.writeHead(200, {"Content-Type": "text/plain"});
  response.write("Hello World");
  response.end();
}

http.createServer(onRequest).listen(8888);

console.log("Server has started.");

this writes to console on a request from my chrome browser:

Request received Request received

Two times? Why?

like image 638
Piddien Avatar asked Nov 26 '25 10:11

Piddien


1 Answers

It was your browser asking for favicon.ico

like image 170
dwerner Avatar answered Nov 29 '25 03:11

dwerner



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!