0
0
Node.jsframework~10 mins

Why streams are needed in Node.js - Test Your Understanding

Choose your learning style9 modes available
Practice - 5 Tasks
Answer the questions below
1fill in blank
easy

Complete the code to create a readable stream from a file.

Node.js
const fs = require('fs');
const readable = fs.createReadStream([1]);
Drag options to blanks, or click blank then click option'
A'input.txt'
B'write.txt'
C'output.txt'
D'config.json'
Attempts:
3 left
💡 Hint
Common Mistakes
Using a file name meant for writing instead of reading.
2fill in blank
medium

Complete the code to pipe data from a readable stream to a writable stream.

Node.js
readableStream.[1](writableStream);
Drag options to blanks, or click blank then click option'
Awrite
Bpipe
Csend
Dtransfer
Attempts:
3 left
💡 Hint
Common Mistakes
Using methods that don't exist on streams like 'write' or 'send'.
3fill in blank
hard

Fix the error in the code to handle stream errors properly.

Node.js
readableStream.on('error', [1]);
Drag options to blanks, or click blank then click option'
Aconsole.info
Bconsole.warn
Cconsole.log
Dconsole.error
Attempts:
3 left
💡 Hint
Common Mistakes
Using console.log which is less clear for errors.
4fill in blank
hard

Fill both blanks to create a writable stream and write data to it.

Node.js
const writable = fs.createWriteStream([1]);
writable.[2]('Hello, streams!');
Drag options to blanks, or click blank then click option'
A'output.txt'
Bwrite
Cend
D'input.txt'
Attempts:
3 left
💡 Hint
Common Mistakes
Using the input file name for writing or using the wrong method like 'end' to write data.
5fill in blank
hard

Fill all three blanks to create a transform stream that modifies data.

Node.js
const { Transform } = require('stream');
const upperCaseTransform = new Transform({
  transform(chunk, encoding, callback) {
    this.push(chunk.toString().[1]());
    callback();
  }
});
readableStream.[2](upperCaseTransform).[3](writableStream);
Drag options to blanks, or click blank then click option'
AtoUpperCase
Bpipe
DtoLowerCase
Attempts:
3 left
💡 Hint
Common Mistakes
Using toLowerCase instead of toUpperCase or missing pipe connections.