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");
});