Deploy a Bun application on Railway

Deploy a Bun application to Railway from the CLI or dashboard, with optional PostgreSQL setup and automatic SSL

Railway is an infrastructure platform: you provision infrastructure, develop against it locally, then deploy to the cloud. Railway 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:

Deploy on Railway

Prerequisites:

  • A Bun application ready for deployment
  • A Railway account
  • Railway CLI (for CLI deployment method)
  • A GitHub account (for Dashboard deployment method)

Method 1: Deploy via CLI#

Step 1

Install the Railway CLI.

terminal
bun install -g @railway/cli

Step 2

Log into your Railway account.

terminal
railway login

Step 3

After authenticating, initialize a new project.

terminal
railway init

Step 4

After initializing the project, add a new database and service.

Step 4 is only necessary if your application uses a database. If you don't need PostgreSQL, skip to Step 5.
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 5

After creating and connecting the services, 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.

terminal
# Deploy your application
railway up

# Generate public domain
railway domain

Your app is now live. railway up deploys your local directory rather than a GitHub repository. To have Railway auto-deploy on every GitHub push, connect the service to your repository with railway service source connect --repo <owner>/<repo> --branch <branch>.


Method 2: Deploy via Dashboard#

Step 1

Create a new project

  1. Go to Railway Dashboard
  2. Click "+ New""GitHub repo"
  3. Choose your repository

Step 2

Add a PostgreSQL database, and connect this database to the service

Step 2 is only necessary if your application uses a database. If you don't need PostgreSQL, skip to Step 3.
  1. Click "+ New""Database""Add PostgreSQL"
  2. After Railway creates the database, select your service (not the database)
  3. Go to "Variables" tab
  4. Click "+ New Variable""Add Reference"
  5. Select DATABASE_URL from postgres

Step 3

Generate a public domain

  1. Select your service
  2. Go to "Settings" tab
  3. Under "Networking", click "Generate Domain"

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


Configuration (Optional)#

By default, Railway uses Railpack to automatically detect and build your Bun application with zero configuration.

Railpack detects Bun from your bun.lock and installs the latest version of Bun unless you pin one with the engines.bun or packageManager field in package.json. Railway's previous builder, Nixpacks, is in maintenance mode.

If your service still builds with Nixpacks, switch it to Railpack by adding the following to your railway.json:

railway.json
{
  "$schema": "https://railway.com/railway.schema.json",
  "build": {
    "builder": "RAILPACK"
  }
}

For more build configuration settings, see the Railway documentation.