Challenge - 5 Problems
Writable Stream Master
Get all challenges correct to earn this badge!
Test your skills under time pressure!
❓ component_behavior
intermediate2:00remaining
What is the output when writing data to a Writable stream?
Consider the following Node.js code using a Writable stream. What will be printed to the console?
Node.js
import { Writable } from 'stream'; const writable = new Writable({ write(chunk, encoding, callback) { console.log(chunk.toString()); callback(); } }); writable.write('Hello'); writable.write('World'); writable.end();
Attempts:
2 left
💡 Hint
Remember that each write call triggers the write method separately.
✗ Incorrect
Each call to writable.write sends a chunk to the write method, which logs it with a newline. So 'Hello' and 'World' are printed on separate lines.
📝 Syntax
intermediate2:00remaining
Which option correctly implements a Writable stream that converts input to uppercase?
Select the option that correctly creates a Writable stream which converts all written data to uppercase before logging it.
Attempts:
2 left
💡 Hint
The write method must accept three parameters and call callback when done.
✗ Incorrect
Option A correctly defines write with (chunk, encoding, callback) and calls callback after logging uppercase string. Others miss callback or use wrong chunk methods.
🔧 Debug
advanced2:00remaining
Why does this Writable stream code cause a runtime error?
Examine the code below. Why does it throw an error when writing data?
Node.js
import { Writable } from 'stream'; const writable = new Writable({ write(chunk, encoding, callback) { const data = chunk.toUpperCase(); console.log(data); callback(); } }); writable.write('test');
Attempts:
2 left
💡 Hint
Check the type of chunk and what methods it supports.
✗ Incorrect
chunk is a Buffer object, which does not have a toUpperCase method. You must convert it to string first.
❓ state_output
advanced2:00remaining
What is the final value of 'data' after writing to this Writable stream?
Given the following code, what will be the value of the variable 'data' after all writes complete?
Node.js
import { Writable } from 'stream'; let data = ''; const writable = new Writable({ write(chunk, encoding, callback) { data += chunk.toString(); callback(); } }); writable.write('Node'); writable.write('JS'); writable.end();
Attempts:
2 left
💡 Hint
Consider how the chunks are concatenated without extra characters.
✗ Incorrect
Each chunk is converted to string and appended directly, so 'Node' + 'JS' = 'NodeJS'. No spaces or newlines are added.
🧠 Conceptual
expert3:00remaining
Which option best explains backpressure handling in Writable streams?
In Node.js Writable streams, what does the return value of the write() method indicate and how should it be handled?
Attempts:
2 left
💡 Hint
Think about how streams signal when they can accept more data.
✗ Incorrect
When write() returns false, it signals the buffer is full and the producer must wait for 'drain' event before writing more to avoid memory issues.