Skip to main content
In Bun, Response objects can accept a Node.js Readable. This works because Bun’s Response object allows any async iterable as its body. Node.js streams are async iterables, so you can pass them directly to Response.
https://mintcdn.com/bun-1dd33a4e-claude-bun-git-module/aYd6IH1DX0gD-k_I/icons/typescript.svg?fit=max&auto=format&n=aYd6IH1DX0gD-k_I&q=85&s=49fc2d2e9587ce2222ea6cc2b60db513server.ts
import { Readable } from "stream";
import { serve } from "bun";
serve({
  port: 3000,
  fetch(req) {
    return new Response(Readable.from(["Hello, ", "world!"]), {
      headers: { "Content-Type": "text/plain" },
    });
  },
});