Typorithm · easy

Bun.serve

bun-servebunserverfetchresponse
Saved on this device
Full lesson · 8 learning steps Open any exercise for focused practice
1

Step 1 of 8 · intro card

Learn Bun.serve

0%

Bun APIs

Bun.serve starts a fast built-in HTTP server. Its fetch handler receives a Web-standard Request and must return a Web-standard Response — the same fetch API you use in the browser.

Bun.serve creates an HTTP server entirely in native code, so there is no need for a framework like Express to handle the basics.

The fetch handler is the heart of the server: it is called once per request with a Web-standard Request object and returns a Response.

Because it speaks the Web fetch standard, the same handler shape works across Bun, browsers, and edge runtimes — you return new Response(body, init).

01

Bun.serve starts a built-in HTTP server.

02

fetch(req) handles each request.

03

Return a Web-standard Response.

const server = Bun.serve({
  port: 3000,
  fetch(req) {
    return new Response("Hello");
  },
});

Read the implementation

Connect each part of the code to the concept before you type.

1. Start a server

Bun.serve spins up a fast built-in HTTP server with no external dependencies.

Bun.serve({

2. Listen port

The port option chooses which TCP port the server binds to.

port: 3000,

3. Request handler

The fetch handler receives a Web-standard Request and runs once per incoming request.

fetch(req) {

4. Web Response

You return a Web-standard Response object, exactly like in browsers and other runtimes.

return new Response("Hello");

A complete learning loop

01

Understand

Read the concept map and follow the code breakdown.

02

Reconstruct

Type the implementation, repair mistakes and work through every recall exercise.

03

Verify

Use the final check without hints; revisit weak concepts in short practice sessions.

Bun.serve: Lesson & Practice · Typorithm | ApplyDjinn