> ## Documentation Index
> Fetch the complete documentation index at: https://docs.sevalla.com/llms.txt
> Use this file to discover all available pages before exploring further.

> ## Agent Instructions
> These are the docs for Sevalla, a platform for deploying applications, databases, static sites, object storage and load balancers. The dashboard is at https://app.sevalla.com.
> Bold text in steps is an exact dashboard label.
> To act on a Sevalla account, prefer the Sevalla MCP server (https://mcp.sevalla.com/mcp, see https://docs.sevalla.com/ai-agents/overview.md), then the Sevalla CLI (https://docs.sevalla.com/developer-tools/cli.md), then the REST API (https://api-docs.sevalla.com, OpenAPI spec at https://api.sevalla.com/v3/openapi.json).
> Every page index is at https://docs.sevalla.com/llms.txt.

# Deploy a Bun application

> Deploy a Bun HTTP server to Sevalla from a Git repository: commit bun.lock so Nixpacks installs Bun, add a start script, or build a newer Bun from a Dockerfile.

A Bun server runs on Sevalla as an application: Nixpacks sees `bun.lock` in your Git repository, installs Bun and the dependencies, and the web process runs `bun run start`. `Bun.serve()` reads the port that Sevalla sets in the `PORT` environment variable on its own.

## Before you begin

* A Sevalla company with a payment method, and a GitHub, GitLab or Bitbucket account for the repository. See [Git providers](/git/overview).
* Bun 1.3 or later on your computer.

## Create the project

Create a project with `bun init`, which writes `index.ts`, `package.json`, `bun.lock` and a `.gitignore`:

```bash theme={null}
mkdir storefront && cd storefront
bun init -y
```

Replace `index.ts` with a server:

```ts index.ts theme={null}
const server = Bun.serve({
  routes: {
    "/": new Response("Hello from Bun on Sevalla"),
  },
  fetch() {
    return new Response("Not Found", { status: 404 });
  },
});

console.log(`Listening on ${server.url}`);
```

`Bun.serve()` takes its port from `BUN_PORT`, `PORT` or `NODE_PORT` when you don't pass one, and listens on `0.0.0.0` by default. Sevalla sets [`PORT`](/guides/javascript/overview#listen-on-the-port-environment-variable) to the web process's port (`8080` by default), so the server needs no port setting.

## Prepare the project for Sevalla

Add a start script to `package.json`:

```json package.json theme={null}
{
  "scripts": {
    "start": "bun run index.ts"
  }
}
```

Keep the other fields that `bun init` wrote. Commit `bun.lock`: Nixpacks, the default [build strategy](/applications/builds/nixpacks), detects Bun from `bun.lock` (or `bun.lockb`) or from a `packageManager` field that names Bun. It then installs Bun 1.3.0, runs `bun i --no-save` and starts the web process with `bun run start`. Without a lockfile or that field, Nixpacks treats the project as a Node.js project and `bun` isn't installed. Bun runs TypeScript directly, so the project needs no build step.

Run `bun start` and open `http://localhost:3000` to check the server locally. Then commit everything and push it to your Git provider:

```bash theme={null}
git init
git add .
git commit -m "Prepare for Sevalla"
git branch -M main
git remote add origin https://github.com/acme/storefront.git
git push -u origin main
```

## Deploy to Sevalla

<Steps>
  <Step title="Create the application">
    In the sidebar, click **Applications**, then click **Create** > **Application**. Under **Source**, click **Private repository**, then choose the **Git provider**, the **Repository** and the **Branch**. Under **Location**, choose a **Data center**. Keep the **Size** at **H1** or choose a larger one, then click **Create application**. The application opens on its **Overview** tab with the status **Not deployed yet**: creating an application doesn't deploy it.
  </Step>

  <Step title="Deploy">
    Click the **Overview** tab, then click **Deploy now** under **Recent deployments**. Check the **Branch** and click **Deploy**.
  </Step>

  <Step title="Turn on auto-deploy">
    To deploy every push to the branch automatically, click the **Settings** tab, then click **Update auto-deploy** in the **Auto-deploy** section. Turn on **Auto-deploy** and click **Update auto-deploy**. See [Deployments](/applications/deployments#deploy-automatically-on-push).
  </Step>
</Steps>

## Verify the deployment

1. On the **Deployments** tab, wait for the deployment's status to change to **Deployed**. The application's status next to its name changes to **Running**.
2. Click the domain under the application's name, for example `storefront-x7k2m.sevalla.app`. The page shows `Hello from Bun on Sevalla`.

<Frame>
  <img className="block dark:hidden" src="https://assets.sevalla.com/screenshots/light/app-overview-address.png" alt="The application header with its name, Running status, repository, branch and the domain that opens the application" width="1192" />

  <img className="hidden dark:block" src="https://assets.sevalla.com/screenshots/dark/app-overview-address.png" alt="The application header with its name, Running status, repository, branch and the domain that opens the application" width="1192" />
</Frame>

If the deployment fails, open it on the **Deployments** tab and read its build log, then see [Troubleshoot builds and deployments](/applications/troubleshooting/builds-and-deployments). A log that runs `npm` instead of `bun` means Nixpacks didn't find `bun.lock` in the repository.

## Deploy changes

With **Auto-deploy** on, every push to the branch starts a deployment; otherwise, click **Deploy now** for each change. Each deployment builds the image, then replaces the web process's instances. See [Deployments](/applications/deployments).

## Use a newer Bun version

Nixpacks 1.41 always installs Bun 1.3.0. To run a newer release, build the application from a Dockerfile based on the official `oven/bun` image.

<Steps>
  <Step title="Add a Dockerfile">
    Create `Dockerfile` in the repository root, commit it and push it:

    ```dockerfile Dockerfile theme={null}
    FROM oven/bun:1.4
    WORKDIR /app

    COPY package.json bun.lock ./
    RUN bun install --frozen-lockfile --production

    COPY . .

    USER bun
    CMD ["bun", "run", "index.ts"]
    ```
  </Step>

  <Step title="Set the build strategy">
    Click the application's **Settings** tab, then click **Update build strategy**. Choose **Dockerfile**, keep the **Dockerfile path** at `Dockerfile` and the **Docker context** at `.`, and click **Update build strategy**.
  </Step>

  <Step title="Deploy">
    Click the **Overview** tab, then click **Deploy now** under **Recent deployments**. Check the **Branch** and click **Deploy**.
  </Step>
</Steps>

See [Dockerfile](/applications/builds/dockerfile) for the other Dockerfile settings.

## Add a custom domain

To serve the application from your own domain, such as `shop.example.com`, add the domain on the application's **Domains** tab and create the DNS records that Sevalla shows. Custom domains need a web process larger than **H1**, so [scale](/applications/scaling) the web process first. See [Custom domains](/domains/overview).

## Connect a database

Create a [database](/databases/create) in the same location as the application, then [connect the application to it](/databases/connect#connect-an-application) with **Add environment variables to the application** turned on. Sevalla adds `DB_URL`, `DB_HOST`, `DB_PORT`, `DB_DATABASE`, `DB_USERNAME` and `DB_PASSWORD` to the application ([what each one holds](/databases/connect#environment-variables-an-internal-connection-adds)), and they apply at the next deployment. Bun's built-in SQL client reads a PostgreSQL URL: `import { SQL } from "bun"`, then `new SQL(process.env.DB_URL)`.


This documentation is built and hosted on [Mintlify](https://mintlify.com), a developer documentation platform.