Deploy Bun Apps
×


Deploy Bun Apps

113

๐Ÿš€ Introduction to Deploying Bun Apps

Bun has taken the JavaScript world by storm with its speed and simplicity. But writing a fast app is only half the battle โ€” the other half is **getting it live**. In this guide, weโ€™ll walk you through various ways to deploy your Bun apps, whether you're using a VPS, Docker, or edge functions.

๐Ÿงฐ Prerequisites

Before deploying, make sure youโ€™ve done the following:

  • โœ… Installed Bun globally on your development machine
  • โœ… Your app is working locally via bun run or bun dev
  • โœ… GitHub repo (optional but helpful)

๐Ÿ“ Directory Structure Example

my-bun-app/
โ”œโ”€โ”€ bun.lockb
โ”œโ”€โ”€ index.ts
โ”œโ”€โ”€ package.json
โ”œโ”€โ”€ tsconfig.json
โ””โ”€โ”€ public/

This is a standard structure. Your entry point (like index.ts) is what youโ€™ll run during deployment.

๐ŸŒ Deploying to a Linux VPS

If you're deploying on a VPS (like DigitalOcean, Hetzner, or AWS EC2), follow these steps:

# Step 1: SSH into your server
ssh user@your-server-ip

# Step 2: Install Bun on the server
curl -fsSL https://bun.sh/install | bash

# Step 3: Clone your repo or upload files
git clone https://github.com/your-user/my-bun-app.git
cd my-bun-app

# Step 4: Install dependencies
bun install

# Step 5: Start the app
bun index.ts

For production, use pm2 or a systemd service to keep the app running even after disconnection or crashes.

๐Ÿณ Dockerize Your Bun App

Want portability? Letโ€™s containerize it using Docker.

# Dockerfile
FROM oven/bun

WORKDIR /app
COPY . .
RUN bun install

CMD ["bun", "index.ts"]
# Build and run
docker build -t my-bun-app .
docker run -p 3000:3000 my-bun-app

This is especially useful for CI/CD pipelines, microservices, or scaling on Kubernetes.

โš™๏ธ Deploying with Bun Serve

If youโ€™re using Bun.serve() to run an HTTP server, make sure the port is exposed correctly:

// index.ts
Bun.serve({
  port: 3000,
  fetch(req) {
    return new Response("๐Ÿงก Hello from Bun!");
  }
});

When hosted, this will be accessible at http://your-domain.com:3000.

๐ŸŒ Reverse Proxy with NGINX

Use NGINX as a reverse proxy to route requests to your Bun server. Example config:

# /etc/nginx/sites-available/my-bun-app
server {
  listen 80;
  server_name your-domain.com;

  location / {
    proxy_pass http://localhost:3000;
    proxy_http_version 1.1;
    proxy_set_header Upgrade $http_upgrade;
    proxy_set_header Connection 'upgrade';
    proxy_set_header Host $host;
    proxy_cache_bypass $http_upgrade;
  }
}

Reload NGINX and youโ€™re live: sudo systemctl reload nginx

โšก Edge Deployment with Vercel (Experimental)

Bun is not natively supported by Vercel (as of now), but you can deploy Bun-written logic via edge functions using adapters like hono or compile Bun apps to WASM in the future. Stay tuned โ€” this is evolving fast!

๐Ÿ”„ Setting Up Auto-Deploy with GitHub Actions

Want to deploy automatically when you push code? Set up a GitHub Actions workflow:

# .github/workflows/deploy.yml
name: Deploy Bun App

on:
  push:
    branches: [ "main" ]

jobs:
  deploy:
    runs-on: ubuntu-latest
    steps:
      - uses: actions/checkout@v3
      - name: Install Bun
        run: curl -fsSL https://bun.sh/install | bash
      - name: Install dependencies
        run: bun install
      - name: Run app (for testing)
        run: bun index.ts

For production deployments, combine this with SSH or Docker push to remote.

โœ… Final Thoughts

Deploying Bun apps is straightforward, thanks to its simplicity and speed. Whether you're using a basic VPS setup, containerizing with Docker, or testing edge deployments, Bun keeps the dev experience fast and modern.

As the ecosystem grows, we expect more native support from cloud providers. Until then โ€” keep hacking, keep deploying, and let Bun cook! ๐Ÿณ๐Ÿ”ฅ



If youโ€™re passionate about building a successful blogging website, check out this helpful guide at Coding Tag โ€“ How to Start a Successful Blog. It offers practical steps and expert tips to kickstart your blogging journey!

For dedicated UPSC exam preparation, we highly recommend visiting www.iasmania.com. It offers well-structured resources, current affairs, and subject-wise notes tailored specifically for aspirants. Start your journey today!



Best WordPress Hosting


Share:


Discount Coupons

Get a .COM for just $6.98

Secure Domain for a Mini Price



Leave a Reply


Comments
    Waiting for your comments

Coding Tag WhatsApp Chat