Typorithm · medium

stdin / stdout / stderr

node-stdio-streamsnodejsstdoutstdinstderr
Saved on this device
Full lesson · 8 learning steps Open any exercise for focused practice
1

Step 1 of 8 · intro card

Learn stdin / stdout / stderr

0%

CLI & Process

process.stdout.write sends raw bytes; console.log is a wrapper that formats and adds a newline. process.stdin is a Readable stream you can read piped input from. Send diagnostics to stderr so they don't pollute piped stdout, and check process.stdout.isTTY to detect whether output is an interactive terminal.

process.stdout.write outputs raw text with no trailing newline, while console.log is a convenience wrapper that formats its arguments and appends a newline — use write when you need precise control over the bytes.

process.stdin is a Readable stream, so listening for its "data" event lets your program consume input piped in from another command, the foundation of Unix-style filters.

Send diagnostics and logs to process.stderr so they stay separate from the program's real output on stdout — that way piping stdout to a file or another command stays clean — and check process.stdout.isTTY to tell whether you're writing to an interactive terminal (true) or a pipe/file (false), e.g. to disable colors.

01

console.log wraps stdout.write and adds a newline.

02

process.stdin is a Readable stream for piped input.

03

stderr for diagnostics; isTTY detects a real terminal.

process.stdout.write("no trailing newline")
console.log("adds a newline")          // shorthand for stdout
process.stdin.on("data", (chunk) => process.stdout.write(chunk))
process.stderr.write("diagnostic\n")   // keeps stdout clean for pipes
if (process.stdout.isTTY) showColors()  // false when piped to a file

Read the implementation

Connect each part of the code to the concept before you type.

1. Raw stdout write

process.stdout.write sends bytes verbatim with no added newline, unlike console.log.

process.stdout.write("no trailing newline")

2. console.log

console.log is a convenience wrapper over process.stdout.write that formats arguments and appends a newline.

console.log("adds a newline")          // shorthand for stdout

3. Read piped input

process.stdin is a Readable stream; listening for "data" lets you consume input piped into the program.

process.stdin.on("data", (chunk) => process.stdout.write(chunk))

4. Diagnostics on stderr

Writing logs to stderr keeps them out of stdout, so piping the program's real output stays clean.

process.stderr.write("diagnostic\n")   // keeps stdout clean for pipes

5. Detect a TTY

process.stdout.isTTY is true only when output goes to an interactive terminal, so you can disable colors when piped.

if (process.stdout.isTTY) showColors()  // false when piped to a file

A complete learning loop

01

Understand

Read the concept map and follow the code breakdown.

02

Reconstruct

Type the implementation, repair mistakes and work through every recall exercise.

03

Verify

Use the final check without hints; revisit weak concepts in short practice sessions.

stdin / stdout / stderr: Lesson & Practice · Typorithm | ApplyDjinn