0
0
Node.jsframework~10 mins

Transform streams for processing 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 Transform stream class from the 'stream' module.

Node.js
const { [1] } = require('stream');
Drag options to blanks, or click blank then click option'
AReadable
BDuplex
CWritable
DTransform
Attempts:
3 left
💡 Hint
Common Mistakes
Using Readable or Writable instead of Transform.
Forgetting to import from 'stream' module.
2fill in blank
medium

Complete the code to create a new Transform stream that converts input chunks to uppercase.

Node.js
const upperCaseTransform = new Transform({
  transform(chunk, encoding, callback) {
    this.push(chunk.toString().[1]());
    callback();
  }
});
Drag options to blanks, or click blank then click option'
AtoLowerCase
BtoUpperCase
Csplit
Dtrim
Attempts:
3 left
💡 Hint
Common Mistakes
Using toLowerCase instead of toUpperCase.
Forgetting to convert chunk to string before calling the method.
3fill in blank
hard

Fix the error in the transform function to correctly handle asynchronous processing.

Node.js
const delayTransform = new Transform({
  async transform(chunk, encoding, callback) {
    await new Promise(resolve => setTimeout(resolve, 100));
    this.push(chunk);
    [1]();
  }
});
Drag options to blanks, or click blank then click option'
Acallback
Breturn
Cresolve
Ddone
Attempts:
3 left
💡 Hint
Common Mistakes
Not calling callback, causing the stream to hang.
Calling a non-existent function like done or resolve.
4fill in blank
hard

Fill both blanks to create a Transform stream that filters out chunks shorter than 5 characters.

Node.js
const filterShort = new Transform({
  transform(chunk, encoding, callback) {
    if (chunk.toString().[1] >= 5) {
      this.push(chunk);
    }
    [2]();
  }
});
Drag options to blanks, or click blank then click option'
Alength
Bsize
Ccount
Dcallback
Attempts:
3 left
💡 Hint
Common Mistakes
Using 'size' or 'count' which are not string properties.
Forgetting to call callback(), causing the stream to stall.
5fill in blank
hard

Fill all three blanks to create a Transform stream that appends '!' to each chunk and converts it to a string.

Node.js
const exclaimTransform = new Transform({
  transform(chunk, encoding, callback) {
    const modified = chunk.toString() + [1];
    this.push(modified.[2]());
    [3]();
  }
});
Drag options to blanks, or click blank then click option'
A'!'
BtoUpperCase
Ccallback
Dtrim
Attempts:
3 left
💡 Hint
Common Mistakes
Not appending the exclamation mark as a string.
Using trim instead of toUpperCase.
Forgetting to call callback().