A server that answers everything
Chapter 1 of six: an empty folder, Node 24 and a server that says Hello to every request. No dependencies, now or later.
This series builds an HTTP server in TypeScript from an empty folder, without a framework and without a single dependency. Six chapters, one a fortnight. By the end it routes, logs, checks a token, has tests and runs under systemd. It is the server stummel ran on for its first year.
You need Node 24, which runs TypeScript files directly by stripping the types. No build step.
The folder
$ mkdir tiny-server && cd tiny-server
$ npm init -y
$ mkdir srcEleven lines
import { createServer } from 'node:http';
const handle = () => new Response('Hello');
createServer(async (req, res) => {
const response = await handle();
res.writeHead(response.status, Object.fromEntries(response.headers));
res.end(await response.text());
}).listen(process.env.PORT ?? 8080, () => {
console.log(`Listening on :${process.env.PORT ?? 8080}`);
});$ node src/server.ts
Listening on :8080
$ curl localhost:8080
Hellohandle returns a Response from the start, though nothing needs it yet. Chapter 2 explains why.
subscribe
New entries and the next chapter by mail, nothing else.