This guide will help you deploy a Bun application on Zerops quickly.
Prerequisites
Deploy Using a Recipe
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
Wait for deployment
Zerops will build and deploy automatically (2-3 minutes).
Access your app
Open the subdomain URL from the IP addresses & Public Routing section.
Deploy Your Own Bun App
1. Create a Bun Service
Click Add new service
Select Bun
Choose version (1.0, 1.1, or latest)
Set hostname (e.g., “api”)
project :
name : my-project
services :
- hostname : api
type : [email protected]
minContainers : 1
maxContainers : 6
zcli project project-import description.yaml
2. Create Your Bun Application
Initialize a new Bun project:
Create a simple server:
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 :
- 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
Push code to Git repository
In Zerops: Deploy → From Git
Enter repository URL
Connect to PostgreSQL
Add Database Service
services :
- hostname : db
type : postgresql@16
mode : NON_HA
Install PostgreSQL Client
Use in Your App
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:
Install dependencies
Add package
Remove package
bun add express
bun add -d @types/express
Build Commands
Common Bun build patterns:
Simple build
With TypeScript
With tests
buildCommands :
- bun install
- bun build ./server.ts --outdir ./dist
buildCommands :
- bun install
- bun build ./src/index.ts --outdir ./dist --target bun
buildCommands :
- bun install
- bun test
- bun build ./server.ts --outdir ./dist
Environment Variables
Go to service settings
Environment Variables
Add variables
run :
envVariables :
NODE_ENV : production
PORT : 3000
API_URL : https://api.example.com
Access in your app:
const apiUrl = process . env . API_URL ;
const port = process . env . PORT || 3000 ;
Running Scripts
Define scripts in 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:
Next Steps
Build Pipeline Configuration Learn how to configure builds with zerops.yaml.