0
0
Node.jsframework~10 mins

process.stdin and process.stdout 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 read input from the user using process.stdin.

Node.js
process.stdin.setEncoding('[1]');
Drag options to blanks, or click blank then click option'
Abinary
Bascii
Cutf8
Dhex
Attempts:
3 left
💡 Hint
Common Mistakes
Using 'ascii' which does not support all characters.
Using 'binary' which is for raw data, not text.
2fill in blank
medium

Complete the code to write 'Hello World' to the console using process.stdout.

Node.js
process.stdout.[1]('Hello World\n');
Drag options to blanks, or click blank then click option'
Awrite
Bread
Cend
Don
Attempts:
3 left
💡 Hint
Common Mistakes
Using 'read' which is for input streams.
Using 'end' which closes the stream.
3fill in blank
hard

Fix the error in the code to correctly listen for data input from process.stdin.

Node.js
process.stdin.on('[1]', (data) => {
  console.log('You typed:', data);
});
Drag options to blanks, or click blank then click option'
Ainput
Breadable
Cwrite
Ddata
Attempts:
3 left
💡 Hint
Common Mistakes
Using 'input' which is not a valid event.
Using 'write' which is for output streams.
4fill in blank
hard

Fill both blanks to create a program that reads a line and then ends the input stream.

Node.js
process.stdin.setEncoding('[1]');
process.stdin.on('[2]', (input) => {
  console.log('Input:', input);
  process.stdin.end();
});
Drag options to blanks, or click blank then click option'
Autf8
Bdata
Creadable
Dascii
Attempts:
3 left
💡 Hint
Common Mistakes
Using 'ascii' encoding which may not handle all characters.
Listening to 'readable' event but not handling data properly.
5fill in blank
hard

Fill all three blanks to create a program that reads input, converts it to uppercase, and writes it back.

Node.js
process.stdin.setEncoding('[1]');
process.stdin.on('[2]', (chunk) => {
  const upper = chunk.[3]();
  process.stdout.write(upper);
});
Drag options to blanks, or click blank then click option'
Autf8
Bdata
CtoUpperCase
DtoLowerCase
Attempts:
3 left
💡 Hint
Common Mistakes
Using 'toLowerCase' instead of 'toUpperCase'.
Listening to wrong event name.
Not setting encoding and getting buffer instead of string.