Beginner LevelExpress JS
When should you call res.end() without a payload to terminate an HTTP connection?
❓ Interview Prompt: Explain res.end(), terminating HTTP requests without body payloads, and 204 No Content / 304 Not Modified responses.
'res.end()' quickly ends the HTTP response process without sending any body payload.
Primary Use Cases:
1
HTTP 204 No Content: Ending requests (like DELETE operations or preflight OPTIONS) where no response body is required.
2
HTTP 304 Not Modified: Ending cached requests where client browser cache is still valid.
3
Manual Stream Piping: Ending custom binary data stream pipes.
Code Implementation Example
javascript
import express from 'express';
const app = express();
app.delete('/api/items/:id', (req, res) => {
// Item deleted successfully; return 204 No Content and terminate response immediately!
res.status(204).end();
});💡Terminating HTTP responses without body payload using res.status(204).end().
🎯 Interview Key Takeaway
Use res.end() to terminate HTTP responses immediately when no response body payload is required (e.g. 204 No Content).
#res.end#Responses#HTTP Status#Beginner
Back to all Express JS Questions→