jsrosetta

I/O

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.

Minimum versions
Node.js ≥ 18Go ≥ 1.22Rust ≥ 1.85Swift ≥ 5.7Java ≥ 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 and Go ship an HTTP server right in their standard library — no framework needed to get started. Rust's std doesn't — it needs a crate like axum (routing + path params as concise as Go's ServeMux). Swift is the same: Foundation has no HTTP server, so the example below parses just the first request line by hand over Network.framework — good enough for a demo, not a spec-compliant HTTP server. Java has had com.sun.net.httpserver.HttpServer (the jdk.httpserver module) for a long time, matching paths by prefix rather than a pattern with wildcards.

Routed server

import http from 'node:http'
 
function handler(request, response) {
  response.writeHead(200, { 'Content-type':'text/plain' })
  response.write('hello world')
  response.end()
}
 
const server = http.createServer(handler)
server.listen(8080)
$ curl http://localhost:8080
hello world

Client (http_client.js, run while a server from above is up): the global fetch() replaces http.get()/http.request() for simple requests.

const response = await fetch('http://localhost:8080')
console.log(await response.text())
$ node http_client.js
hello world
# only applies to the servers with a /hello/{name} route (Go, Rust, Swift, Java) — the JS server above has no such route
$ curl http://localhost:8080/hello/gopher
hello gopher

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