jsrosetta

I/O

Writing to Stdout and Stderr

How Node.js's process.stdout.write/process.stderr.write compares to fmt.Fprint (Go), io::Write (Rust), FileHandle (Swift), and System.out/err.write (Java).

Minimum versions
Node.js ≥ 12.20Go ≥ 1.0Rust ≥ 1.0Swift ≥ 3.0Java ≥ 25
Verified on
Node.js 24.12.0Go 1.27.1Rust 1.98.1Swift 6.2.4Java 25.0.4.1

Node.js code is an ES module: save it as .mjs or set "type": "module" in package.json.

console.log/console.error covers most needs, but sometimes you need to write straight to a stream without an extra newline or formatting. All five languages let you write directly to stdout/stderr as a stream/writer: Go uses fmt.Fprint, Rust uses the io::Write trait, Swift uses FileHandle, and Java writes raw bytes through System.out/System.err (both a PrintStream).

Writing to stdout

process.stdout.write('hello world\n')
hello world

Writing to stderr

process.stderr.write('hello error\n')
hello error

Reference: github.com/miguelmota/golang-for-nodejs-developers#stdout