How do I fix ERR_HTTP_HEADERS_SENT when trying to send both HTML and JS to clients?

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

You can’t send multiple files in one request, why not break them into two separate requests?

2 Likes

So how would I do that? (I’m quite a noob with Node.js and web development)