-
Why does Express give "Cannot set headers after they are sent to the client"? |
Beta Was this translation helpful? Give feedback.
Answered by
TatyOko28
Feb 9, 2025
Replies: 1 comment
-
This happens when you try to send multiple responses in a single request. Incorrect: app.get("/test", (req, res) => {
res.send("Hello");
res.send("World"); // Error: Headers already sent
}); Correct: Return after sending a response app.get("/test", (req, res) => {
res.send("Hello");
return;
}); |
Beta Was this translation helpful? Give feedback.
0 replies
Answer selected by
Mercure28
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
This happens when you try to send multiple responses in a single request.
Incorrect:
Correct: Return after sending a response