在 Render 上部署 Bun 应用
Render 是一个用于构建、部署和扩展应用的云平台。
它提供来自 GitHub 的自动部署、全球 CDN、私有网络、自动 HTTPS 设置,以及托管的 PostgreSQL 和兼容 Redis 的 Key Value 存储。
Render 原生支持 Bun。你可以将 Bun 应用作为 Web 服务、后台工作进程、定时任务等进行部署。
作为示例,本指南将 Express HTTP 服务器部署到 Render。
- 步骤 1
创建一个名为
myapp的新的 GitHub 仓库。将其克隆到本地。shellgit clone git@github.com:my-github-username/myapp.git cd myapp - 步骤 2
添加 Express 库。
shellbun add express - 步骤 3
使用 Express 定义一个服务器:
app.ts
import express from "express"; const app = express(); const port = process.env.PORT || 3001; app.get("/", (req, res) => { res.send("Hello World!"); }); app.listen(port, () => { console.log(`Listening on port ${port}...`); }); - 步骤 4
提交你的更改并推送到 GitHub。
terminalgit add app.ts bun.lock package.json git commit -m "Create simple Express app" git push origin main - 步骤 5
在你的 Render 控制面板 中,点击
New>Web Service并连接你的myapp仓库。 - 步骤 6
在 Render 界面中,创建 Web 服务时填写以下内容:
运行环境 (Runtime) Node构建命令 (Build Command) bun install启动命令 (Start Command) bun app.ts
构建完成后,你的 Web 服务就会通过分配的 onrender.com URL 上线。