Reputation: 63
I'll construct the following basic example that abstracts away a bunch of implementation details of my program to convey the core question. Let's say I have:
const http = require("http");
const server = http.createServer((req, res) => {
console.log("request event");
res.end("Hello World");
});
server.listen(5000, () => {
console.log(server.listening); // true
console.log("Server listening on port: 5000...");
});
Obviously my terminal shows Server listening on port: 5000..., but every time I refresh my browser I get two "request event" instances logged. I've had this happen a lot of times in the past and never really bothered with it, but why does this happen?
Upvotes: 0
Views: 480
Reputation: 255
const server = http.createServer((req, res) => {
console.log(req.url)
console.log("request event");
res.end("Hello World");
});
server.listen(5000, () => {
console.log(server.listening); // true
console.log("Server listening on port: 5000...");
});
One for your request and one for favicon.ico sent by default from browser
Upvotes: 0
Reputation: 21
There are always two requests that by default browser requests.
I hope this answers your question.
Upvotes: 2
Reputation: 1605
The reason is, browsers by default requests for favicon.ico. That's why you see two request event.
Upvotes: 2