Render 是一个云平台,让你可以灵活地构建、部署和扩展应用程序。
它提供诸如从 GitHub 自动部署、全球 CDN、私有网络、自动 HTTPS 设置以及托管 PostgreSQL 和 Redis 等功能。
Render 原生支持 Bun。你可以将 Bun 应用程序部署为 Web 服务、后台工作器、定时任务等。
作为示例,让我们将一个简单的 Express HTTP 服务器部署到 Render。
步骤 1
创建一个名为 myapp 的新 GitHub 仓库。在本地克隆它。
sh
git clone git@github.com:my-github-username/myapp.git
cd myapp步骤 2
添加 Express 库。
sh
bun add express步骤 3
使用 Express 定义一个简单的服务器:
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。
sh
git 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 UI 中,在创建 Web 服务时提供以下值:
| Runtime | Node |
| Build Command | bun install |
| Start Command | bun app.ts |
就是这样!构建完成后,你的 Web 服务将在分配的 onrender.com URL 上上线。