0

This code has a console.log statement that outputs twice and I don't understand why. Does anyone have an idea about why this is happening?

const http = require("http");
const fs = require("fs");
const _ = require("lodash");

const server = http.createServer((req, res) => {
  console.log("hey there"); //this outputs two times in the console for a request

  res.setHeader("Content-Type", "text/html");

  fs.readFile("./views/index.html", (err, data) => {
    if (err) {
      console.log("error");
      res.end();
    } else {
      res.end(data);
    }
  });
});

server.listen(3000, "localhost", () => {
  console.log("this is up and running in port 3000");
});
5eb
  • 14,798
  • 5
  • 21
  • 65

1 Answers1

0

when you send a request with browser two requests sent to the server that one of them is about http://localhost:3000/favicon.ico like the photo

enter image description here

it's better send a request with postman

Mohammad Yaser Ahmadi
  • 4,664
  • 3
  • 17
  • 39