Question:
How do I fix ERR_HTTP_HEADERS_SENT when trying to send both HTML and JS to clients?
Repl link:
https://replit.com/@NotThatGuyOWOT/chatty
// in index.js
console.log("[init] sending index.html...");
app.get("/", (req, res) => {
fs.readFile("./client/pages/index.html", function(err, data) {
res.writeHead(200, {"Content-Type": "text/html"});
res.write(data);
return res.end();
});
fs.readFile("./client/pages/client.js", function(err, data) {
res.writeHead(200, {"Content-Type": "text/javascript"});
res.write(data);
return res.end();
}); // this is commented out
});