0
0
Node.jsframework~5 mins

process.stdin and process.stdout in Node.js - Cheat Sheet & Quick Revision

Choose your learning style9 modes available
Recall & Review
beginner
What is process.stdin in Node.js?

process.stdin is a readable stream that lets your Node.js program receive input from the user through the terminal or command line.

Click to reveal answer
beginner
What does process.stdout do in Node.js?

process.stdout is a writable stream that allows your program to send output to the terminal or command line, showing messages or results to the user.

Click to reveal answer
intermediate
How do you listen for user input using process.stdin?

You attach a listener to the data event on process.stdin. This event fires whenever the user types something and presses enter.

process.stdin.on('data', (input) => { console.log(`You typed: ${input}`); });
Click to reveal answer
beginner
How can you write a message to the terminal using process.stdout?

You use the write() method on process.stdout to send text to the terminal without adding a new line automatically.

process.stdout.write('Hello, user!');
Click to reveal answer
intermediate
Why might you use process.stdin.setEncoding('utf8')?

This sets the input encoding so that the data you receive from process.stdin is a readable string instead of raw bytes, making it easier to work with text input.

Click to reveal answer
What type of stream is process.stdin in Node.js?
AWritable stream
BTransform stream
CDuplex stream
DReadable stream
Which method do you use to send output to the terminal with process.stdout?
Awrite()
Bread()
Con()
Dpipe()
How do you listen for user input from the terminal in Node.js?
Aprocess.stdout.on('data', callback)
Bprocess.stdin.on('data', callback)
Cprocess.stdin.write('data')
Dprocess.stdout.write('data')
What does process.stdin.setEncoding('utf8') do?
AConverts input to a string
BConverts output to uppercase
CStops input from being read
DChanges output color
Which of these is true about process.stdout.write()?
AIt automatically adds a new line
BIt never outputs to the terminal
CIt writes text to the terminal without a new line
DIt reads user input
Explain how process.stdin and process.stdout work together in a Node.js program.
Think about how your program talks and listens in the terminal.
You got /5 concepts.
    Describe how to set up a simple Node.js program that asks the user for their name and then greets them.
    Imagine a friendly chat with the user in the terminal.
    You got /5 concepts.