jsrosetta

Basics

Printing

How Node.js's console.log/console.error map to Go's fmt.Println/Printf, Rust's println!/eprint!, Swift's print, and Java 25's IO.println.

Minimum versions
Node.js ≥ 12.20Go ≥ 1.0Rust ≥ 1.19Swift ≥ 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.

Node.js's console.log writes to stdout, and console.error writes to stderr. Go splits this into clearer functions: fmt.Println prints with a trailing newline, fmt.Printf takes a C-style format string, and fmt.Fprintf writes to any io.Writer — including os.Stderr. Rust has equivalent macros (println!/eprint!) built into the language; Swift only has a plain print, so it needs Foundation for C-style formatting and for writing to stderr; Java 25 adds IO.println for compact source files, while System.err still works as before.

Printing to stdout and stderr

console.log('print to stdout')
console.log('format %s %d', 'example', 1)
console.error('print to stderr')
print to stdout
format example 1
print to stderr

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