Runtime
Bundler
Package Manager
Test Runner
Guides
Reference
Blog
Install Bun
Guides HTTP & Networking

Streaming HTTP Server with Node.js Streams

In Bun, a Response accepts a Node.js Readable as its body.

This works because Bun's Response accepts any async iterable as its body, and Node.js streams are async iterables.

server.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" },
    });
  },
});

On this page

No Headings