Railway is the fastest way to deploy a full-stack application with a real server — not serverless functions. One project holds your app, its database, Redis cache, and any other services, all networked together privately. This guide covers the complete setup from a fresh repository to a live application.

What Railway Is and Isn't

Railway runs your application as a persistent process — like a traditional server, but managed and autoscaled. Unlike Vercel, there's no function-per-route model. You deploy a single server (Node.js, Python, Go, etc.) that stays running.

This makes Railway ideal for: LLM agent backends with long-running requests, WebSocket servers, background job processors, and any application that needs more than 60 seconds of execution time.

Step 1: Install the Railway CLI

npm install -g @railway/cli
railway login

Step 2: Create a Project and Deploy

# From your project directory
railway init
 
# Deploy the current directory
railway up
 
# Railway detects your runtime automatically:
# Node.js: looks for package.json + start script
# Python: looks for requirements.txt or pyproject.toml
# Docker: uses Dockerfile if present
Railway uses Nixpacks to detect and build your project automatically. If you have unusual requirements, add a Dockerfile and Railway will use it instead.

Step 3: Add a PostgreSQL Database

Railway offers managed Postgres, MySQL, Redis, and MongoDB as one-click additions within a project. They are provisioned in the same private network as your app service.

  1. In the Railway dashboard, open your project
  2. Click New > Database > Add PostgreSQL
  3. Railway provisions the database in under 30 seconds
  4. The DATABASE_URL variable is automatically injected into your service
# Your app reads DATABASE_URL from the environment
import os
import psycopg2
 
conn = psycopg2.connect(os.environ['DATABASE_URL'])
 
# Or with SQLAlchemy
from sqlalchemy import create_engine
engine = create_engine(os.environ['DATABASE_URL'])

Step 4: Set Environment Variables

# Set a variable via CLI
railway variables set OPENAI_API_KEY=sk-...
 
# Set multiple at once from a .env file
railway variables set --from .env.production
 
# View all current variables
railway variables
Railway does not automatically read .env files during deployment. You must explicitly set variables via the CLI or dashboard. The DATABASE_URL and REDIS_URL for Railway-managed services are injected automatically — do not set them manually.

Step 5: Configure Your Start Command

Railway uses the start script from your package.json by default. For Python apps, specify the start command in the Railway dashboard or a railway.toml file.

# railway.toml
[deploy]
startCommand = "gunicorn app:app --bind 0.0.0.0:$PORT --workers 4"
healthcheckPath = "/health"
healthcheckTimeout = 30
Railway injects the PORT environment variable automatically. Always bind your server to 0.0.0.0:$PORT, not a hardcoded port.

Step 6: Add a Custom Domain

  1. In your service settings, click Settings > Domains
  2. Click Generate Domain for a free railway.app subdomain, or Add Custom Domain
  3. For custom domains, add the CNAME record shown to your DNS provider
  4. Railway provisions SSL automatically

Step 7: Set Up Automatic Deployments

Connect your GitHub repository for automatic deployments on every push. In the service settings, link your repo and select the branch to deploy. Railway builds and deploys on every push, with zero downtime if your health check passes.

Monitoring and Logs

# Stream live logs from your service
railway logs
 
# Open the Railway dashboard for the current project
railway open
Metadata Value
Title Deploy a Full-Stack App on Railway: The Complete Setup Guide
Tool Railway
Primary SEO keyword deploy app railway
Secondary keywords railway deployment guide, railway postgres, railway environment variables, railway cli
Estimated read time 8 minutes
Research date 2026-04-14