Recall & Review
beginner
What is a stream in Node.js?
A stream is a way to handle reading or writing data piece by piece, instead of all at once. It helps process large files efficiently without using much memory.
Click to reveal answer
beginner
Why might loading an entire file into memory be a problem?
Loading a whole file at once can use a lot of memory, especially if the file is large. This can slow down or crash your program if memory runs out.
Click to reveal answer
intermediate
Name two types of streams in Node.js.
Readable streams (for reading data) and writable streams (for writing data). There are also duplex streams that can do both.
Click to reveal answer
intermediate
How do streams improve performance when working with large files?
Streams process data in small chunks, so they use less memory and start working immediately without waiting for the whole file to load.
Click to reveal answer
beginner
What Node.js module is commonly used to work with file streams?
The built-in 'fs' module provides methods like createReadStream() and createWriteStream() to work with file streams.
Click to reveal answer
What happens when you load a large file entirely into memory in Node.js?
✗ Incorrect
Loading a large file fully uses much memory and can slow or crash the program.
Which method creates a readable stream for a file in Node.js?
✗ Incorrect
fs.createReadStream() creates a stream to read a file piece by piece.
Streams in Node.js process data in:
✗ Incorrect
Streams handle data in small chunks to save memory and improve speed.
Which is NOT a benefit of using streams?
✗ Incorrect
Streams do not automatically compress files; they just handle data flow efficiently.
What type of stream can both read and write data?
✗ Incorrect
Duplex streams can read and write data, combining both capabilities.
Explain in simple terms why streams are better than loading entire files into memory for large files.
Think about how you eat a big pizza: slice by slice, not all at once.
You got /4 concepts.
Describe how you would use Node.js streams to read a large file and write its content to another file.
Imagine passing water from one bucket to another using a pipe.
You got /4 concepts.