Railway
Deploy to Railway
Railway offers simple infrastructure with a great developer experience.
Setup
1. Create Project
- Go to railway.app/new
- Choose "Deploy from GitHub repo"
- Select your repository
2. Configure Service
Railway auto-detects Next.js. Configure for monorepo:
- Click on your service
- Go to Settings → Build
- Set Root Directory:
apps/web - Set Build Command:
pnpm build - Set Start Command:
pnpm start
3. Environment Variables
Add environment variables in the Variables tab:
DATABASE_URL=postgresql://...
BETTER_AUTH_SECRET=your-secret-key
PORT=30004. Deploy
Railway automatically deploys on push to your default branch.
Database on Railway
Railway can host your PostgreSQL database:
1. Add PostgreSQL
- Click "New" → "Database" → "PostgreSQL"
- Railway provisions a database
2. Connect
Use the connection string from the database service:
- Click on the PostgreSQL service
- Go to Variables
- Copy
DATABASE_URL - Add to your web service variables
Or use Railway's variable references:
DATABASE_URL=${{Postgres.DATABASE_URL}}Custom Domain
- Go to your service → Settings → Domains
- Add your custom domain
- Update DNS records
Networking
Private Networking
Services in the same project can communicate privately:
# Reference another service
API_URL=${{api.RAILWAY_PRIVATE_DOMAIN}}Public Access
Enable public networking for your web service to expose it to the internet.
Scaling
Railway supports horizontal scaling:
- Go to Settings → Deploy
- Adjust replicas
- Configure health checks
Troubleshooting
Build Failures
Check the build logs. Common issues:
- Missing
PORTenvironment variable - Incorrect root directory
- pnpm not detected (add
packageManagerto package.json)
Database Connection
If database connections fail:
- Ensure
DATABASE_URLis set - Check the database service is running
- Verify connection pooling settings
Next Steps
- Railway Docs — Full documentation
- Railway Templates — Pre-built configurations