Skip to main content
This guide will help you deploy a Bun application on Zerops quickly.

Prerequisites

Deploy Using a Recipe

1

Log in to Zerops

Navigate to app.zerops.io.
2

Import the project

Click Import a project and paste:
project:
  name: my-bun-app
  tags:
    - bun

services:
  - hostname: api
    type: [email protected]
    enableSubdomainAccess: true
    buildFromGit: https://github.com/zeropsio/recipe-bun

  - hostname: db
    type: postgresql@16
    mode: NON_HA
    priority: 1
3

Wait for deployment

Zerops will build and deploy automatically (2-3 minutes).
4

Access your app

Open the subdomain URL from the IP addresses & Public Routing section.

Deploy Your Own Bun App

1. Create a Bun Service

  1. Click Add new service
  2. Select Bun
  3. Choose version (1.0, 1.1, or latest)
  4. Set hostname (e.g., “api”)

2. Create Your Bun Application

Initialize a new Bun project:
bun init
Create a simple server:
server.ts
import { serve } from "bun";

const server = serve({
  port: 3000,
  fetch(req) {
    return new Response("Hello from Bun on Zerops!");
  },
});

console.log(`Listening on http://localhost:${server.port}`);

3. Add zerops.yaml

zerops.yaml
zerops:
  - setup: api
    build:
      base: [email protected]
      buildCommands:
        - bun install
        - bun build ./server.ts --outdir ./dist
      deployFiles:
        - dist
        - node_modules
        - package.json
      cache: node_modules
    
    run:
      base: [email protected]
      ports:
        - port: 3000
          httpSupport: true
      start: bun run dist/server.js

4. Deploy

  1. Push code to Git repository
  2. In Zerops: DeployFrom Git
  3. Enter repository URL

Connect to PostgreSQL

Add Database Service

services:
  - hostname: db
    type: postgresql@16
    mode: NON_HA

Install PostgreSQL Client

bun add pg

Use in Your App

server.ts
import { serve } from "bun";
import { Pool } from "pg";

const pool = new Pool({
  host: "db",  // Service hostname
  port: 5432,
  user: "db",
  password: process.env.DB_PASSWORD,
  database: "db",
});

const server = serve({
  port: 3000,
  async fetch(req) {
    const result = await pool.query("SELECT NOW() as time");
    
    return new Response(
      JSON.stringify({ time: result.rows[0].time })
    );
  },
});

console.log(`Listening on http://localhost:${server.port}`);
Services in the same project communicate via private network using hostnames.

Package Management

Bun has a fast built-in package manager:
bun install

Build Commands

Common Bun build patterns:
buildCommands:
  - bun install
  - bun build ./server.ts --outdir ./dist

Environment Variables

  1. Go to service settings
  2. Environment Variables
  3. Add variables
Access in your app:
const apiUrl = process.env.API_URL;
const port = process.env.PORT || 3000;

Running Scripts

Define scripts in package.json:
package.json
{
  "name": "my-bun-app",
  "scripts": {
    "start": "bun run server.ts",
    "dev": "bun --watch server.ts",
    "build": "bun build ./server.ts --outdir ./dist",
    "test": "bun test"
  }
}
Use in zerops.yaml:
run:
  start: bun start

Next Steps

Build Pipeline Configuration

Learn how to configure builds with zerops.yaml.

Build docs developers (and LLMs) love