> ## 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.

# 使用 Express 和 Bun 构建 HTTP 服务器

Express 和其他主要的 Node.js HTTP 库应该开箱即用。Bun 实现了这些库依赖的 [`node:http`](https://nodejs.org/api/http.html) 和 [`node:https`](https://nodejs.org/api/https.html) 模块。

<Note>
  更多详细的兼容性信息，请参阅 [运行时 > Node.js API](/runtime/nodejs-compat#node-http) 页面。
</Note>

```sh terminal icon="terminal" theme={"theme":{"light":"github-light","dark":"dracula"}}
bun add express
```

***

使用 Express 定义一个 HTTP 路由并启动服务器：

```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 express from "express";

const app = express();
const port = 8080;

app.get("/", (req, res) => {
  res.send("Hello World!");
});

app.listen(port, () => {
  console.log(`Listening on port ${port}...`);
});
```

***

在 `localhost` 上启动服务器：

```sh terminal icon="terminal" theme={"theme":{"light":"github-light","dark":"dracula"}}
bun server.ts
```
