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
1
Step 1
Install the Railway CLI.
terminal
2
Step 2
Log into your Railway account.
terminal
3
Step 3
After authenticating, initialize a new project.
terminal
4
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
5
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.
terminal
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
1
Step 1
Create a new project
- Go to Railway Dashboard
- Click ”+ New” → “GitHub repo”
- Choose your repository
2
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.
- 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_URLfrom postgres
3
Step 3
Generate a public domain
- Select your service
- Go to “Settings” tab
- Under “Networking”, click “Generate Domain”
Configuration (Optional)
By default, Railway uses Railpack to automatically detect and build your Bun application with zero configuration. Railpack detects Bun from yourbun.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