Skip to content

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 服務時提供以下值:

RuntimeNode
Build Commandbun install
Start Commandbun app.ts

就是這樣!構建完成後,你的 Web 服務將在分配的 onrender.com URL 上上線。

你可以查看 部署日志 獲取詳細信息。請參閱 Render 文檔 獲取在 Render 上部署的完整概述。

Bun學習網由www.bunjs.com.cn整理維護