Skip to main content

Streaming HTTP Server with Node.js Streams

还没翻译译自英文(bun.com)本页 3 段都还没译

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.

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" },
    });
  },
});
Traducción © 2026 fanyi.dev · Original © 2026 the Bun project (LICENSE.md names no copyright holder) (MIT)