C.W.K.
Stream
Lesson 06 of 07 · published

Node.js and Bun: Backend TS

~8 min · frameworks, node, bun, backend

Level 0Curious
0 XP0/93 lessons0/23 achievements
0/100 XP to next level100 XP to go0% complete
"Backend TypeScript: pick the runtime, write the code, type-check separately."

Node + tsx vs Bun

For TypeScript on the backend, two practical paths in 2026:

Node + tsx: Node.js with the tsx wrapper (npx tsx server.ts). Tsx uses esbuild under the hood to transpile on the fly. Works with every Node-compatible library; the dev experience is unified through tsc --noEmit for type checking.

Bun: Native TypeScript runtime (bun run server.ts). Faster startup, built-in test runner, bundler, package manager. Most Node-compatible libraries work; some Node internals need adapters.

Express/Fastify/Hono with TypeScript

The popular Node frameworks all have first-class TypeScript types. Express requires @types/express; Fastify and Hono ship their own types.

Hono is the new lightweight contender — designed for the edge (Cloudflare Workers, Bun, Deno) and TypeScript-first. The route handlers have inferred parameter and body types when you use its validation middleware.

The shared shape

Whichever you pick, the TypeScript story is the same: write .ts, run with a TS-aware runtime/wrapper, type-check separately. The differences are speed, library compatibility, and ergonomics — not the type system.

For new backend TS in 2026, default to Bun + Hono for speed, Node + Express for compatibility. Both are valid; the choice depends on your project's other constraints.

Code

A minimal Hono + Bun server·typescript
// Hono + Bun — modern minimal example.
import { Hono } from 'hono';

const app = new Hono();

app.get('/', (c) => c.text('Hello from Hono'));

app.get('/users/:id', (c) => {
  const id = c.req.param('id');     // id: string — typed
  return c.json({ id, name: `User ${id}` });
});

export default app;

// Run with: bun run server.ts
// or with Node + tsx: npx tsx server.ts (Hono works on both)
Express + Node + tsx — established stack·typescript
// Express + Node + tsx — classic stack.
import express, { Request, Response } from 'express';

const app = express();
app.use(express.json());

app.get('/users/:id', (req: Request<{ id: string }>, res: Response) => {
  const { id } = req.params;     // id: string
  res.json({ id, name: `User ${id}` });
});

app.listen(3000);

// Run with: npx tsx server.ts
// Or build first: npx tsc && node dist/server.js

External links

Exercise

Build a 'hello world' HTTP server in TypeScript. Try it twice: once with Bun + Hono, once with Node + tsx + Express. Time the startup. Note which one's types feel cleaner.
Hint
Bun's startup is consistently faster — often noticeably for small servers. Hono's API has fewer footguns than Express's (express.Request<{ id: string }> can be tricky). For new code, Hono is the modern default; Express is fine if you have existing investment.

Progress

Progress is local-only — sign in to sync across devices.
Spotted a bug or have feedback on this page?Report an Issue

Comments 0

🔔 Reply notifications (sign in)
Sign inPlease sign in to comment.

No comments yet — be the first.