0
0
Node.jsframework~10 mins

Reading data with Readable streams in Node.js - Interactive Code Practice

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

Complete the code to import the Readable stream module.

Node.js
const { [1] } = require('stream');
Drag options to blanks, or click blank then click option'
AReadable
BWritable
CTransform
DDuplex
Attempts:
3 left
💡 Hint
Common Mistakes
Choosing Writable which is for writing data.
Choosing Transform or Duplex which are for other stream types.
2fill in blank
medium

Complete the code to create a readable stream from an array of strings.

Node.js
const readable = Readable.from([1]);
Drag options to blanks, or click blank then click option'
A['hello', 'world']
B{hello: 'world'}
C'hello world'
D12345
Attempts:
3 left
💡 Hint
Common Mistakes
Passing a single string instead of an array.
Passing an object which is not iterable.
Passing a number which is invalid.
3fill in blank
hard

Fix the error in the code to read data chunks from the stream.

Node.js
readable.on('data', ([1]) => {
  console.log(chunk.toString());
});
Drag options to blanks, or click blank then click option'
Abuffer
Bdata
Cchunk
Dstream
Attempts:
3 left
💡 Hint
Common Mistakes
Using a different parameter name than the one used inside the function.
Using a reserved word like 'data' as parameter but not matching usage.
4fill in blank
hard

Fill both blanks to correctly handle the end of the readable stream.

Node.js
readable.on('[1]', () => {
  console.log('[2]');
});
Drag options to blanks, or click blank then click option'
Aend
Bfinish
Cclose
Dend of stream reached
Attempts:
3 left
💡 Hint
Common Mistakes
Using 'finish' which is for writable streams.
Using 'data' which is for data chunks.
Using 'close' which is different and less common here.
5fill in blank
hard

Fill all three blanks to create a readable stream and log all data chunks and the end event.

Node.js
const { [1] } = require('stream');

const data = ['Node', 'JS', 'Streams'];
const readable = [2].from(data);

readable.on('data', ([3]) => {
  console.log([3].toString());
});
Drag options to blanks, or click blank then click option'
AReadable
Cchunk
Dbuffer
Attempts:
3 left
💡 Hint
Common Mistakes
Using different names for import and usage.
Using wrong parameter names in the event handler.
Not calling from() on the Readable class.