Railway Deployment Cheat Sheet

Last Updated: November 21, 2025

Installation & Setup

npm install -g @railway/cli
Install Railway CLI globally
railway login
Authenticate with Railway account
railway init
Initialize project in current directory
railway link
Link existing Railway project
railway unlink
Unlink project from directory
railway logout
Log out of Railway CLI
railway whoami
Show current logged-in user

Deployment

railway up
Deploy current directory to Railway
railway up --detach
Deploy without streaming logs
railway up --service backend
Deploy to specific service
railway redeploy
Trigger redeployment without code changes
railway status
Show deployment status
railway open
Open project in browser

Environment Variables

railway variables
List all environment variables
railway variables set KEY=value
Set environment variable
railway variables set KEY=value KEY2=value2
Set multiple variables at once
railway variables delete KEY
Delete environment variable
railway variables --environment production
List variables for specific environment
railway run npm start
Run command with Railway environment
railway run --environment production node app.js
Run with specific environment variables
railway variables --json > vars.json
Export variables to JSON file

Services

railway service
List all services in project
railway service create
Create new service
railway service delete
Delete service
railway service link
Link current directory to service

Logs & Monitoring

railway logs
Stream deployment logs
railway logs --service backend
Logs for specific service
railway logs --deployment d-abc123
Logs for specific deployment
railway logs --follow
Follow logs in real-time

Databases & Plugins

railway add
Add database or plugin to project
railway add --database postgres
Add PostgreSQL database
railway add --database mysql
Add MySQL database
railway add --database mongodb
Add MongoDB database
railway add --database redis
Add Redis cache
railway connect postgres
Connect to PostgreSQL shell
railway connect redis
Connect to Redis CLI

Environments

railway environment
List all environments
railway environment create staging
Create new environment
railway environment delete staging
Delete environment
railway environment --environment production
Switch to production environment

Domains & URLs

railway domain
Show current domain
railway domain create example.com
Add custom domain
railway domain delete example.com
Remove custom domain
railway open
Open deployed app in browser

Projects & Teams

railway list
List all projects
railway create
Create new Railway project
railway delete
Delete current project
railway whoami
Show current user and team

Configuration Files

railway.json
Project configuration file
railway.toml
Alternative config format (TOML)
{ "build": { "builder": "NIXPACKS" } }
Specify build system in railway.json
{ "deploy": { "startCommand": "npm start" } }
Custom start command
{ "deploy": { "restartPolicyType": "ON_FAILURE" } }
Set restart policy

CLI Options

--help
Show help for command
--version
Show CLI version
--json
Output in JSON format
--environment production
Specify environment for command
--service backend
Specify service for command

Environment Variables (Built-in)

$RAILWAY_ENVIRONMENT
Current environment name
$RAILWAY_PROJECT_ID
Project identifier
$RAILWAY_SERVICE_ID
Service identifier
$RAILWAY_DEPLOYMENT_ID
Current deployment ID
$RAILWAY_PUBLIC_DOMAIN
Public domain for service
$RAILWAY_PRIVATE_DOMAIN
Private internal domain
$PORT
Port to listen on (auto-assigned)

Best Practices

railway run npm run dev
Test with production env vars locally
railway variables --environment staging
Use separate staging environment
railway logs --follow
Monitor deployments in real-time
process.env.PORT || 3000
Always use Railway's PORT variable
railway add --database postgres
Use Railway databases for auto-configuration
💡 Pro Tip: Railway auto-injects DATABASE_URL and other connection strings when you add databases. Use `railway run` locally to test with production environment variables!
← Back to Data Science & ML | Browse all categories | View all cheat sheets