Railway is an infrastructure platform where you can provision infrastructure, develop with that infrastructure locally, and then deploy to the cloud. It enables instant deployments from GitHub with zero configuration, automatic SSL, and built-in database provisioning.
This guide walks through deploying a Bun application with a PostgreSQL database (optional), which is exactly what the template below provides.
You can either follow this guide step-by-step or simply deploy the pre-configured template with one click:
Prerequisites:
- A Bun application ready for deployment
- A Railway account
- Railway CLI (for CLI deployment method)
- A GitHub account (for Dashboard deployment method)
Step 1
Ensure sure you have the Railway CLI installed.
bun install -g @railway/cli
Step 2
Log into your Railway account.
railway login
Step 3
After successfully authenticating, initialize a new project.
# Initialize project
bun-react-postgres$ railway init
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.
# Add PostgreSQL database. Make sure to add this first!
bun-react-postgres$ railway add --database postgres
# Add your application service.
bun-react-postgres$ railway add --service bun-react-db --variables DATABASE_URL=\${{Postgres.DATABASE_URL}}
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. To make your app publicly accessible, you need to generate a public domain.
# Deploy your application
bun-nextjs-starter$ railway up
# Generate public domain
bun-nextjs-starter$ railway domain
Step 1
Create a new project
- Go to Railway Dashboard
- Click "+ New" → "GitHub repo"
- Choose your repository
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.
- Click "+ New" → "Database" → "Add PostgreSQL"
- After the database has been created, select your service (not the database)
- Go to "Variables" tab
- Click "+ New Variable" → "Add Reference"
- Select
DATABASE_URL
from postgres
Step 3
Generate a public domain
- Select your service
- Go to "Settings" tab
- Under "Networking", click "Generate Domain"
Your app is now live! Railway auto-deploys on every GitHub push.
By default, Railway uses Nixpacks to automatically detect and build your Bun application with zero configuration.
However, using the Railpack application builder provides better Bun support, and will always support 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
:
{
"$schema": "https://railway.com/railway.schema.json",
"build": {
"builder": "RAILPACK"
}
}
For more build configuration settings, check out the Railway documentation.