LOGBOOK

HELP

Quiz Entry - updated: 2026.07.14

What is the difference between res.send() and res.write()?

res.send() writes data and closes the response in one call, whereas res.write() appends a chunk and leaves the response open for more.

// res.send() - complete response in one call
router.get('/simple', (req, res) => {
    // Sends and ends
    res.send('Hello World');
});

// res.write() - build response incrementally
router.get('/stream', (req, res) => {
    res.write('Part 1\n');
    res.write('Part 2\n');
    // Must call end() manually
    res.end();
});

When to use each:

Method Use Case
res.send() Most responses (simple, complete)
res.write() Streaming, large files, SSE

Note: After res.send(), you cannot send more data. Calling it twice causes an error.

From Quiz: WEBT / Backend Development | Updated: Jul 14, 2026