Whenever I make http requests to a server using node.js, the console.logs inside the http request function output twice. I set up a sever with the following code, and used localhost:8888 on firefox to make a request (localhost:8888):
var http = require('http');
var url = require('url');
function onRequest(request, response) {
var pathname = url.parse(request.url, true).pathname;
console.log("Your url pathname is " + pathname);
response.write("Did you get your response?");
}
var new_server = http.createServer(onRequest).listen(8888);
The console prints:
Your url pathname is /
Your url pathname is /favicon.ico
My questions are:
- Why is the request sent twice?
- Why is the pathname favicon.ico on the second request despite the fact that I did not specify anything after the socket number in the request url?
- Is there any way you can fix these two issues?
Thank you.