Bun

指南生态系统

使用 Express 和 Bun 构建 HTTP 服务器

Express 以及其他主流的 Node.js HTTP 库应该都能开箱即用。Bun 实现了一些这些库所依赖的 node:httpnode:https 模块。

有关更详细的兼容性信息,请参阅 运行时 > Node.js API 页面。

bun add express

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

server.ts
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 上启动服务器

bun server.ts