jsrosetta

const you = new NodeDeveloper();

Write Node.js? Read every other language.

Each post takes a familiar JavaScript concept and sets it next to the equivalent code in other languages. Pick a language in any code block and the whole page follows.

Basics

Comments

Line (`//`) and block (`/* */`) comments use the exact same syntax across all five languages — the only difference is doc-comment convention.

  • Node.js
  • Go
  • Rust
  • Swift
  • Java

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.

  • Node.js
  • Go
  • Rust
  • Swift
  • Java

Logging

How ad-hoc timestamped console.log in Node.js compares to Go's log/log-slog, Rust's tracing crate, Swift's Foundation, and Java's System.Logger.

  • Node.js
  • Go
  • Rust
  • Swift
  • Java

Variables and Constants

What const and let in Node.js correspond to in Go, Rust, Swift, and Java.

  • Node.js
  • Go
  • Rust
  • Swift
  • Java

String Interpolation

How JavaScript's template literals (`${}`) compare to Go's fmt.Sprintf, Rust's format!/println!, Swift's string interpolation, and Java's String.formatted.

  • Node.js
  • Go
  • Rust
  • Swift
  • Java

Types

Types

How JavaScript's primitive and composite types compare to Go's, Rust's, Swift's, and Java's static type systems (int8..uint64, struct, map, channel…).

  • Node.js
  • Go
  • Rust
  • Swift
  • Java

Type Checking

How JavaScript's typeof/Object.prototype.toString compare to Go's reflect.TypeOf, Swift's type(of:), Java's getClass(), and Rust's std::any::type_name.

  • Node.js
  • Go
  • Rust
  • Swift
  • Java

Big Numbers

How JavaScript's BigInt compares to Go's math/big, Java's java.math.BigInteger, and Rust's num-bigint crate — Swift has no built-in big-number type.

  • Node.js
  • Go
  • Rust
  • Swift
  • Java

Weak References: WeakRef and FinalizationRegistry

How Node.js's WeakRef and FinalizationRegistry compare to Go 1.24's weak.Pointer and runtime.AddCleanup: holding a reference without blocking GC, cleaning up after an object is reclaimed, and a cache that releases memory on its own.

  • Node.js
  • Go

Control flow

If/Else

How JavaScript's if/else if/else and ternary operator compare to Go (no ternary), Rust (if is an expression), and Swift/Java (both have a ternary).

  • Node.js
  • Go
  • Rust
  • Swift
  • Java

For Loops

How JavaScript's C-style for loop compares to Go (C-style + range-over-int since 1.22), Java (keeps C-style), and Rust/Swift (no C-style for, only range).

  • Node.js
  • Go
  • Rust
  • Swift
  • Java

While Loops

How JavaScript's while loop maps to Go's for used as a while loop (Go has no while keyword) — Rust, Swift, and Java all have while like JavaScript.

  • Node.js
  • Go
  • Rust
  • Swift
  • Java

Switch

How JavaScript's switch/case compares to Go (no fallthrough by default, explicit fallthrough), Rust's match (no fallthrough concept), Swift (like Go), and Java (like JS).

  • Node.js
  • Go
  • Rust
  • Swift
  • Java

Collections

Arrays

Node.js's slice and concat compared to Go's slice, Rust's Vec, Swift's value-type Array, and Java's ArrayList.

  • Node.js
  • Go
  • Rust
  • Swift
  • Java

Iterating arrays (map, filter, reduce)

Node.js's forEach, map, filter, reduce compared to Rust, Swift, and Java iterators, and hand-written generic Map/Filter/Reduce functions in Go.

  • Node.js
  • Go
  • Rust
  • Swift
  • Java

Sorting arrays

Node.js's Array.prototype.toSorted compared to in-place sorting in Go, Rust, and Java, and Swift's sort()/sorted().

  • Node.js
  • Go
  • Rust
  • Swift
  • Java

Uint8Array

Node.js's Uint8Array (set, subarray, fill) compared to Go's []uint8, Rust's &[u8], Swift's [UInt8], and Java's byte[].

  • Node.js
  • Go
  • Rust
  • Swift
  • Java

Buffer

Node.js's Buffer.alloc, writeUIntBE/LE, and Buffer.compare compared to Go's []byte, Rust's &mut [u8], Swift's [UInt8], and Java's byte[].

  • Node.js
  • Go
  • Rust
  • Swift
  • Java

Map

Node.js's Map (set/get/has/delete, for...of) compared to Go's map[K]V, Rust's HashMap, Swift's Dictionary, and Java's HashMap.

  • Node.js
  • Go
  • Rust
  • Swift
  • Java

Object

Node.js object literals and methods compared to structs/classes with separate methods in Go, Rust, Swift, and Java.

  • Node.js
  • Go
  • Rust
  • Swift
  • Java

Functions

Functions

How Node.js declares functions and parameter types compared to the explicit function signatures of Go, Rust, Swift, and Java.

  • Node.js
  • Go
  • Rust
  • Swift
  • Java

First-Class Functions

First-class functions, closures, and currying in Node.js compared to function values and closures in Go, Rust, Swift, and Java.

  • Node.js
  • Go
  • Rust
  • Swift
  • Java

Default Values

Default parameters in Node.js and Swift compared to Option (Rust), overloading (Java), and pointers + nil (Go).

  • Node.js
  • Go
  • Rust
  • Swift
  • Java

Destructuring

Object destructuring in Node.js compared to struct pattern destructuring in Rust, tuple destructuring in Swift, record patterns in Java, and multiple assignment in Go.

  • Node.js
  • Go
  • Rust
  • Swift
  • Java

Spread and Rest

Node.js's spread and rest operators compared to real variadic parameters in Swift and Java, slice destructuring in Rust, and `...T` in Go.

  • Node.js
  • Go
  • Rust
  • Swift
  • Java

Swapping Variables

Swapping two variables with array destructuring in Node.js compared to destructuring assignment in Rust, the `swap` function in Swift, multiple assignment in Go, and a temporary variable in Java.

  • Node.js
  • Go
  • Rust
  • Swift
  • Java

IIFE

IIFEs in Node.js compared to immediately invoked anonymous functions/closures in Go, Rust, Swift, and Java.

  • Node.js
  • Go
  • Rust
  • Swift
  • Java

Generators

Generator functions and iterator helpers in Node.js compared to Iterator (Rust), AsyncStream (Swift), virtual threads (Java), and `iter.Seq`/channels in Go.

  • Node.js
  • Go
  • Rust
  • Swift
  • Java

Object-oriented

Classes

Classes, private fields, and inheritance in Node.js compared to real classes in Swift/Java, structs + traits in Rust, and structs + embedding in Go.

  • Node.js
  • Go
  • Rust
  • Swift
  • Java

Event Emitter

Node.js's EventEmitter compared to NotificationCenter (Swift), a hand-rolled callback map (Rust, Java), and channels with select in Go.

  • Node.js
  • Go
  • Rust
  • Swift
  • Java

Async

Promises

How Node.js's Promise .then()/.catch() and Promise.all() compare to channels (Go), Future (Rust), async/await (Swift), and CompletableFuture (Java).

  • Node.js
  • Go
  • Rust
  • Swift
  • Java

Async/Await

How Node.js's Promise and async/await compare to goroutines (Go), Future + tokio (Rust), Swift concurrency, and CompletableFuture (Java).

  • Node.js
  • Go
  • Rust
  • Swift
  • Java

Timers: setTimeout and setInterval

How Node.js's setTimeout and setInterval compare to time.AfterFunc/Ticker (Go), std::thread (Rust), Task.sleep (Swift), and ScheduledExecutorService (Java).

  • Node.js
  • Go
  • Rust
  • Swift
  • Java

Streams

How Node.js's Readable/Writable/Transform streams compare to io.Reader/Writer (Go), std::io::Read/Write (Rust), Pipe (Swift), and InputStream (Java).

  • Node.js
  • Go
  • Rust
  • Swift
  • Java

Concurrency: Threads and Child Processes

How Node.js's worker_threads/child_process.fork() compare to goroutines (Go), std::thread (Rust), TaskGroup (Swift), and thread/ProcessBuilder (Java).

  • Node.js
  • Go
  • Rust
  • Swift
  • Java

Message Passing

How Node.js's MessageChannel compares to channels (Go), mpsc (Rust), AsyncStream (Swift), and BlockingQueue (Java) for sending data between tasks.

  • Node.js
  • Go
  • Rust
  • Swift
  • Java

Cancellation: AbortController and context

How Node.js's AbortController/AbortSignal compares to Go's context.Context: cancelling manually, timeouts, combining cancellation signals, and checking for cancellation inside a loop.

  • Node.js
  • Go

Structured concurrency: Promise.all and errgroup

How Node.js's Promise.all/allSettled/any combined with AbortController compare to Go's errgroup, sync.WaitGroup, and channels: cancelling sibling tasks when one fails, limiting concurrency, collecting every result, and taking the fastest one.

  • Node.js
  • Go

Error handling

Error Handling and try/catch

How Node.js's throw and try/catch/finally compare to error values in Go, Result in Rust, throws in Swift, and exceptions in Java.

  • Node.js
  • Go
  • Rust
  • Swift
  • Java

Uncaught Exceptions

How Node.js's process.on('uncaughtException') compares to panic/recover (Go), catch_unwind (Rust), do/catch (Swift), and an uncaught exception handler (Java).

  • Node.js
  • Go
  • Rust
  • Swift
  • Java

Stack Traces

How Node.js's console.trace() compares to debug.Stack() (Go), Backtrace (Rust), callStackSymbols (Swift), and printStackTrace() (Java).

  • Node.js
  • Go
  • Rust
  • Swift
  • Java

Resource Cleanup: using and defer

How Node.js's using/await using, Symbol.dispose, and DisposableStack compare to Go's defer: block vs function scope, LIFO order, and errors during cleanup.

  • Node.js
  • Go

I/O

Reading, Writing, and Deleting Files

How Node.js's readFile/writeFile compares to os.ReadFile/os.WriteFile (Go), std::fs (Rust), FileManager (Swift), and java.nio.file.Files (Java).

  • Node.js
  • Go
  • Rust
  • Swift
  • Java

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).

  • Node.js
  • Go
  • Rust
  • Swift
  • Java

Reading from Stdin

How Node.js's readline/promises compares to bufio.Reader (Go), io::stdin (Rust), readLine() (Swift), and IO.readln (Java) for reading a line of input.

  • Node.js
  • Go
  • Rust
  • Swift
  • Java

Command-Line Arguments and Flags

How Node.js's process.argv/util.parseArgs compares to os.Args/flag (Go), env::args (Rust), CommandLine (Swift), and main's parameter (Java).

  • Node.js
  • Go
  • Rust
  • Swift
  • Java

Environment Variables

How Node.js's process.env compares to os.Getenv (Go), env::var (Rust), ProcessInfo.environment (Swift), and System.getenv (Java).

  • Node.js
  • Go
  • Rust
  • Swift
  • Java

Running Subprocesses (exec)

How Node.js's child_process.execSync/exec compares to os/exec (Go), std::process::Command (Rust), Process (Swift), and ProcessBuilder (Java).

  • Node.js
  • Go
  • Rust
  • Swift
  • Java

TCP Server

How Node.js's net.createServer compares to net.Listen (Go), TcpListener (Rust), Network.framework (Swift), and ServerSocket (Java) for a TCP echo server.

  • Node.js
  • Go
  • Rust
  • Swift
  • Java

UDP Server

How Node.js's dgram.createSocket compares to net.ListenUDP (Go), UdpSocket (Rust), Network.framework (Swift), and DatagramSocket (Java) for receiving datagrams.

  • Node.js
  • Go
  • Rust
  • Swift
  • Java

HTTP Server

How Node.js's http.createServer compares to ServeMux (Go 1.22+), axum (Rust), Network.framework (Swift), and HttpServer (Java) for a routed HTTP server.

  • Node.js
  • Go
  • Rust
  • Swift
  • Java

HTTP Client

How Node.js's global fetch() compares to Go's net/http: GET and reading JSON, POST with headers, 4xx/5xx status codes, timeouts, and streaming the body.

  • Node.js
  • Go

DNS Lookups

How Node.js's node:dns/promises compares to the net package (Go), hickory-resolver (Rust), getaddrinfo (Swift, A/AAAA only), and JNDI (Java) for DNS lookups.

  • Node.js
  • Go
  • Rust
  • Swift
  • Java

Standard library

Date and Time

Node.js's Date and Intl.DateTimeFormat compared to Go's immutable time.Time, Rust's chrono, Swift's Date, and Java's java.time: parsing, adding days, and formatting.

  • Node.js
  • Go
  • Rust
  • Swift
  • Java

Regex

Node.js's RegExp literals compared to Go's regexp, Rust's regex, Swift's Regex literals, and Java's java.util.regex: replace, test, and find all matches.

  • Node.js
  • Go
  • Rust
  • Swift
  • Java

JSON

Node.js's JSON.parse/stringify compared to Go's encoding/json, Rust's serde_json, Swift's Codable, and Java's Jackson for mapping fields.

  • Node.js
  • Go
  • Rust
  • Swift
  • Java

URL Parsing

Node.js's WHATWG URL compared to Go's net/url, Rust's url crate, Swift's URLComponents, and Java's java.net.URI: getting the scheme, user info, port, path, and query.

  • Node.js
  • Go
  • Rust
  • Swift
  • Java

Gzip

Node.js's zlib.gzip/unzip (promisified) compared to Go's compress/gzip, Rust's flate2, Swift's zlib via C interop, and Java's java.util.zip.

  • Node.js
  • Go
  • Rust
  • Swift
  • Java

Crypto (hashing)

Node.js's createHash compared to Go's crypto/sha256, Rust's sha2, Swift's CryptoKit, and Java's MessageDigest for computing a SHA-256 hash.

  • Node.js
  • Go
  • Rust
  • Swift
  • Java

Databases (SQLite)

Node.js's node:sqlite compared to Go's go-sqlite3, Rust's rusqlite, Swift's SQLite3, and Java's sqlite-jdbc: creating a table, inserting, and querying.

  • Node.js
  • Go
  • Rust
  • Swift
  • Java

Managing Modules

Node.js's npm compared to Go modules, Cargo (Rust), Swift Package Manager, and Maven/Gradle (Java): installing, updating, removing, and exporting/importing packages.

  • Node.js
  • Go
  • Rust
  • Swift
  • Java

Writing Tests

Node.js's node:test + node:assert compared to Go's testing, Rust's #[test], Swift Testing, and Java's JUnit for table-driven tests.

  • Node.js
  • Go
  • Rust
  • Swift
  • Java

Benchmarking

Node.js's tinybench compared to Go's testing.B, Rust's criterion, Swift's ContinuousClock, and Java's JMH for measuring function performance.

  • Node.js
  • Go
  • Rust
  • Swift
  • Java

Writing Documentation

Node.js's JSDoc compared to Go's doc comments, Rust's rustdoc, Swift's DocC, and Java's Javadoc, plus examples that run as tests.

  • Node.js
  • Go
  • Rust
  • Swift
  • Java

Data structures

Implementing a dynamic array

Build a dynamic array on top of fixed storage in Node.js, Go and Rust: length, capacity, doubling when full, push/pop/insert/remove and their complexity.

  • Node.js
  • Go
  • Rust