> ## Documentation Index
> Fetch the complete documentation index at: https://bun.zhcndoc.com/llms.txt
> Use this file to discover all available pages before exploring further.

# 使用 Node.js 流的流式 HTTP 服务器

在 Bun 中，[`Response`](https://developer.mozilla.org/en-US/docs/Web/API/Response) 对象可以接受 Node.js 的 [`Readable`](https://nodejs.org/api/stream.html#stream_readable_streams)。

这是因为 Bun 的 `Response` 对象允许任何异步可迭代对象作为其主体。Node.js 流是异步可迭代对象，因此你可以直接将它们传递给 `Response`。

```ts server.ts icon="https://mintcdn.com/bun-zhcndoc/cnUTwgMuf4cCrwC-/icons/typescript.svg?fit=max&auto=format&n=cnUTwgMuf4cCrwC-&q=85&s=e7767043c9e885c34f2d6c8fe2a95217" theme={"theme":{"light":"github-light","dark":"dracula"}}
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" },
    });
  },
});
```
