Express res.end() Method

Beginner
⏱️ 7 min read
📚 Updated: May 2026
🎯 3 Code Examples

What you’ll learn

  • How and when to end responses with res.end().
  • How to send optional final data using res.end(data).
  • How res.end() differs from res.send().
  • How to avoid duplicate response writes.

Syntax

javascript
res.end()
res.end([data[, encoding]])
1

End response with status only

javascript
app.delete('/cache', function (req, res) {
  // Cache cleared...
  res.status(204).end();
});
2

Send quick plain text and end

javascript
app.get('/ping', function (req, res) {
  res.set('Content-Type', 'text/plain; charset=utf-8');
  res.end('pong');
});
3

Guard against double responses

javascript
app.get('/health', function (req, res) {
  if (!process.env.DB_READY) {
    return res.status(503).end('Service unavailable');
  }
  res.json({ ok: true });
});

⚠️ Common pitfalls

  • Do not call res.send(), res.json(), or another res.end() after ending the response.
  • If you send data with res.end(), set relevant headers manually when needed.
  • Use early returns to keep control flow clear after ending responses.

❓ FAQ

It ends the response process and tells Node/Express no more data will be written.
Yes, you can pass a string or buffer as the final response chunk.
res.send() handles content-type/format logic for you, while res.end() is lower-level and more manual.
Use it for lightweight plain responses or low-level streaming/control cases.
Calling another response method after res.end(), causing headers-sent or double-response errors.
Did you know?

res.end() finalizes the HTTP response stream and can optionally send a final data chunk.

About the author

Mari Selvan M P
Mari Selvan M P 🔗

Developer, cloud engineer, and technical writer

  • Experience 12 years building web and cloud systems
  • Focus Full Stack Development, AWS, and Developer Education

I write practical tutorials so students and working developers can learn by doing—from databases and APIs to deployment on AWS.

4 people found this page helpful