What is streaming responses in Express.js and when should you use it?

Answer

Streaming responses send data to the client incrementally as it becomes available rather than buffering the entire response. Express responses are Node.js writable streams — you can pipe data directly: const fileStream = fs.createReadStream('large-file.csv'); fileStream.pipe(res);. For database results: stream a MongoDB cursor to the response. For real-time data, use Server-Sent Events (SSE): set Content-Type: text/event-stream and write events with res.write('data: {msg}\n\n'). Benefits: lower Time-To-First-Byte (client starts processing before the full response arrives), lower memory usage (no buffering gigabytes in RAM), real-time delivery for logs and live data. Handle client disconnects with req.on('close', cleanup).