What if you could send any response with just one simple command?
Why res.send for general responses in Express? - Purpose & Use Cases
Imagine building a web server that must reply to every user request by writing raw HTTP headers and body manually for each response.
Manually crafting HTTP responses is slow, repetitive, and easy to mess up headers or content formatting, leading to broken pages or errors.
Using res.send lets you quickly send responses with proper headers and content formatting automatically handled for you.
response.writeHead(200, {'Content-Type': 'text/html'}); response.write('<h1>Hello</h1>'); response.end();
res.send('<h1>Hello</h1>');You can focus on what to send, not how to send it, making server code simpler and less error-prone.
When a user visits your homepage, res.send quickly delivers the welcome message without you worrying about headers or ending the response.
Manually sending HTTP responses is complex and error-prone.
res.send simplifies sending content with correct headers.
This makes server code cleaner and faster to write.