File Upload with Streams

Large uploads should not be fully loaded into memory.

Streams help process files chunk by chunk.

Why this matters

If 100 users upload 500 MB files and your server loads each file fully into memory, the server can crash.

Streams avoid that by processing chunks.

Simple stream idea

requestStream.pipe(fileWriteStream)

Data flows from request to file.

What production code needs

A real upload feature should handle:

Express note

In Express apps, file uploads are often handled with middleware like Multer or directly with streams depending on the requirement.

But the underlying idea is still Node streams.

Interview answer

File uploads should be handled with streams when files can be large. Streams process data chunk by chunk, reducing memory usage. Production upload code should validate file type and size, handle errors, secure storage paths, and clean up partial uploads.