# Deploy a Bun application on Railway (/docs/guides/deployment/railway)

<!-- agent-signals: reading_time_min: 3 · est_tokens: 1102 · updated: 2026-07-28 -->
Related: [Deploy a Bun application on Vercel](/docs/guides/deployment/vercel.md), [Deploy a Bun application on Render](/docs/guides/deployment/render.md), [Deploy a Bun application on AWS Lambda](/docs/guides/deployment/aws-lambda.md), [Deploy a Bun application on DigitalOcean](/docs/guides/deployment/digital-ocean.md), [Deploy a Bun application on Google Cloud Run](/docs/guides/deployment/google-cloud-run.md)

Railway is an infrastructure platform: you provision infrastructure, develop against it locally, then deploy to the cloud. It deploys from GitHub with zero configuration, handles SSL automatically, and provisions databases.

This guide deploys a Bun application with an optional PostgreSQL database, the same setup the following template provides.

You can either follow this guide step-by-step or deploy the pre-configured template with one click:

<a href="https://railway.com/deploy/bun-react-postgres?referralCode=Bun&utm_medium=integration&utm_source=template&utm_campaign=bun" target="_blank">
  <img src="https://railway.com/button.svg" alt="Deploy on Railway" />
</a>

***

**Prerequisites**:

* A Bun application ready for deployment
* A [Railway account](https://railway.app/)
* Railway CLI (for CLI deployment method)
* A GitHub account (for Dashboard deployment method)

***

## Method 1: Deploy via CLI [#method-1-deploy-via-cli]

<Steps>
  <Step title="Step 1">
    Install the Railway CLI.

    ```bash terminal icon="terminal"
    bun install -g @railway/cli
    ```
  </Step>

  <Step title="Step 2">
    Log into your Railway account.

    ```bash terminal icon="terminal"
    railway login
    ```
  </Step>

  <Step title="Step 3">
    After authenticating, initialize a new project.

    ```bash terminal icon="terminal"
    railway init
    ```
  </Step>

  <Step title="Step 4">
    After initializing the project, add a new database and service.

    <Note>
      Step 4 is only necessary if your application uses a database. If you don't need PostgreSQL, skip to Step 5.
    </Note>

    ```bash terminal icon="terminal"
    # Add PostgreSQL database. Make sure to add this first!
    railway add --database postgres

    # Add your application service.
    railway add --service bun-react-db --variables DATABASE_URL=\${{Postgres.DATABASE_URL}}
    ```
  </Step>

  <Step title="Step 5">
    After the services have been created and connected, deploy the application to Railway. By default, services are only accessible within Railway's private network, so generate a public domain to make your app publicly accessible.

    ```bash terminal icon="terminal"
    # Deploy your application
    railway up

    # Generate public domain
    railway domain
    ```
  </Step>
</Steps>

Your app is now live. Railway auto-deploys on every GitHub push.

***

## Method 2: Deploy via Dashboard [#method-2-deploy-via-dashboard]

<Steps>
  <Step title="Step 1">
    Create a new project

    1. Go to [Railway Dashboard](http://railway.com/dashboard?utm_medium=integration\&utm_source=docs\&utm_campaign=bun)
    2. Click &#x2A;*"+ New"*&#x2A; → &#x2A;*"GitHub repo"**
    3. Choose your repository
  </Step>

  <Step title="Step 2">
    Add a PostgreSQL database, and connect this database to the service

    <Note>
      Step 2 is only necessary if your application uses a database. If you don't need PostgreSQL, skip to Step 3.
    </Note>

    1. Click &#x2A;*"+ New"*&#x2A; → &#x2A;*"Database"*&#x2A; → &#x2A;*"Add PostgreSQL"**
    2. After the database has been created, select your service (not the database)
    3. Go to &#x2A;*"Variables"** tab
    4. Click &#x2A;*"+ New Variable"*&#x2A; → &#x2A;*"Add Reference"**
    5. Select `DATABASE_URL` from postgres
  </Step>

  <Step title="Step 3">
    Generate a public domain

    1. Select your service
    2. Go to &#x2A;*"Settings"** tab
    3. Under &#x2A;*"Networking"*&#x2A;, click &#x2A;*"Generate Domain"**
  </Step>
</Steps>

Your app is now live. Railway auto-deploys on every GitHub push.

***

## Configuration (Optional) [#configuration-optional]

By default, Railway uses [Nixpacks](https://docs.railway.com/guides/build-configuration#nixpacks-options) to automatically detect and build your Bun application with zero configuration.

However, the [Railpack](https://docs.railway.com/guides/build-configuration#railpack) application builder has better Bun support and always supports the latest version of Bun. The pre-configured templates use Railpack by default.

To enable Railpack in a custom project, add the following to your `railway.json`:

```json railway.json icon="file-json"
{
  "$schema": "https://railway.com/railway.schema.json",
  "build": {
    "builder": "RAILPACK"
  }
}
```

For more build configuration settings, see the [Railway documentation](https://docs.railway.com/guides/build-configuration).
