Challenge - 5 Problems
Stream Mastery
Get all challenges correct to earn this badge!
Test your skills under time pressure!
❓ component_behavior
intermediate2:00remaining
What does this Readable stream output?
Consider this Node.js Readable stream code. What will be printed to the console?
Node.js
import { Readable } from 'stream'; const readable = new Readable({ read(size) { this.push('Hello'); this.push('World'); this.push(null); } }); readable.on('data', chunk => console.log(chunk.toString()));
Attempts:
2 left
💡 Hint
Remember that 'data' event emits chunks as they are pushed.
✗ Incorrect
The Readable stream pushes 'Hello' then 'World' as separate chunks. Each 'data' event logs one chunk, so console.log prints each chunk on its own line.
📝 Syntax
intermediate2:00remaining
Which option correctly creates a Writable stream that logs data?
Which code snippet correctly creates a Writable stream that logs each chunk it receives?
Attempts:
2 left
💡 Hint
The write method must accept three arguments and call callback when done.
✗ Incorrect
The write method requires three parameters: chunk, encoding, and callback. It must call callback() to signal completion. Option C follows this correctly.
❓ state_output
advanced2:00remaining
What is the output of this Transform stream?
Given this Transform stream that uppercases input, what will be the final output printed?
Node.js
import { Transform } from 'stream'; const upperCaseTransform = new Transform({ transform(chunk, encoding, callback) { this.push(chunk.toString().toUpperCase()); callback(); } }); upperCaseTransform.on('data', chunk => console.log(chunk.toString())); upperCaseTransform.write('hello '); upperCaseTransform.write('world'); upperCaseTransform.end();
Attempts:
2 left
💡 Hint
Each write triggers a 'data' event with the transformed chunk.
✗ Incorrect
The Transform stream uppercases each chunk separately. The two writes produce two 'data' events, printing 'HELLO ' and 'WORLD' on separate lines.
🔧 Debug
advanced2:00remaining
Why does this Duplex stream cause an error?
This Duplex stream code throws an error. What is the cause?
Node.js
import { Duplex } from 'stream'; const duplex = new Duplex({ read(size) { this.push('data'); this.push(null); }, write(chunk, encoding, callback) { console.log(chunk.toString()); callback(); } });
Attempts:
2 left
💡 Hint
Writable streams must call callback() in write method.
✗ Incorrect
The write method must call callback() to signal completion. Missing this causes the stream to hang or error.
🧠 Conceptual
expert2:00remaining
Which stream type allows simultaneous reading and writing with independent data flows?
In Node.js streams, which type supports both reading and writing independently, allowing data to flow in both directions at the same time?
Attempts:
2 left
💡 Hint
Think about streams that combine reading and writing capabilities.
✗ Incorrect
Duplex streams support both reading and writing independently, allowing two-way data flow simultaneously.