运行时包管理器打包器测试运行器代码检查格式化指南参考博客反馈

在 Render 上部署 Bun 应用

Render 是一个用于构建、部署和扩展应用的云平台。

它提供来自 GitHub 的自动部署、全球 CDN、私有网络、自动 HTTPS 设置,以及托管的 PostgreSQL 和兼容 Redis 的 Key Value 存储。

Render 原生支持 Bun。你可以将 Bun 应用作为 Web 服务、后台工作进程、定时任务等进行部署。


作为示例,本指南将 Express HTTP 服务器部署到 Render。

  1. 步骤 1

    创建一个名为 myapp 的新的 GitHub 仓库。将其克隆到本地。

    shell
    git clone git@github.com:my-github-username/myapp.git
    cd myapp
    
  2. 步骤 2

    添加 Express 库。

    shell
    bun add express
    
  3. 步骤 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. 步骤 4

    提交你的更改并推送到 GitHub。

    terminal
    git add app.ts bun.lock package.json
    git commit -m "Create simple Express app"
    git push origin main
    
  5. 步骤 5

    在你的 Render 控制面板 中,点击 New > Web Service 并连接你的 myapp 仓库。

  6. 步骤 6

    在 Render 界面中,创建 Web 服务时填写以下内容:

    运行环境 (Runtime)Node
    构建命令 (Build Command)bun install
    启动命令 (Start Command)bun app.ts

构建完成后,你的 Web 服务就会通过分配的 onrender.com URL 上线。

查看部署日志以了解详细信息。有关部署的更多信息,请参阅 Render 文档。