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')package main
import (
"fmt"
"os"
)
func main() {
fmt.Println("print to stdout")
fmt.Printf("format %s %v\n", "example", 1)
fmt.Fprintf(os.Stderr, "print to stderr")
}fn main() {
println!("print to stdout");
println!("format {} {}", "example", 1);
eprint!("print to stderr");
}import Foundation
print("print to stdout")
print(String(format: "format \("example") %d", 1))
FileHandle.standardError.write(Data("print to stderr".utf8))void main() {
IO.println("print to stdout");
IO.println("format %s %d".formatted("example", 1));
System.err.print("print to stderr");
}print to stdout
format example 1
print to stderrReference: github.com/miguelmota/golang-for-nodejs-developers#printing