Node.js · Middle · Question 11 of 75

Why use streams to send a 2 GB file instead of readFile?

Explanation

readFile loads the whole file into memory first. With fs.createReadStream(path).pipe(res) only a small buffer is in memory at any time.

Further reading

Problem with a question

Node.js · Middle · question 11

Test yourself

Take the Node.js · Middle quiz: questions and options are shuffled, and you get a review of your mistakes at the end.

Take this quiz