You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

能否将Bunjs用作完整后端服务器?附Express代码运行疑问

Bun 能否作为完整后端服务器使用?

当然可以!Bun 不仅能用来启动 React 前端应用,完全胜任完整后端服务器的角色,而且对 Node.js 生态的兼容性极佳——你提供的 Express 代码直接就能在 Bun 环境下运行。

运行你给出的 Express 代码步骤:

  • 确保已安装 Bun,初始化项目:bun init -y
  • 安装 Express 依赖:bun add express
  • 将代码保存为 index.js
  • 启动服务:bun index.js

启动后访问 http://localhost:3000,就能看到"hello world"的输出。

另外,Bun 自身还提供了性能更出色的原生 HTTP 服务器 API,无需依赖 Express 也能搭建后端,示例代码如下:

const server = Bun.serve({
  port: 3000,
  fetch(req) {
    return new Response("Hello from Bun's native server!");
  },
});

console.log(`Server up at http://localhost:${server.port}`);

内容的提问来源于stack exchange,提问作者Mohamed Kamel

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.08.25 23:33:30