| name | Railway CLI Management |
| description | Deploy, manage services, view logs, and configure Railway infrastructure. Use when deploying to Railway, managing environment variables, viewing deployment logs, scaling services, or managing volumes. |
Railway CLI Management
Master Railway CLI for deployments, service management, log viewing, and infrastructure operations.
Quick Reference
Deployment
railway up
railway up --detach
railway up --service api
railway up --environment production
railway redeploy
railway redeploy --service worker
railway redeploy --yes
railway down
railway down --service api
Service & Project Management
railway list
railway link
railway link <project-id>
railway status
railway status --json
railway open
railway unlink
railway service <service-name-or-id>
railway add
Getting Deployment IDs
Best Method:
railway status --json
railway status --json | jq -r '.services.edges[0].node.serviceInstances.edges[0].node.latestDeployment.id'
railway status --json | jq -r '.services.edges[] | select(.node.name=="api") | .node.serviceInstances.edges[0].node.latestDeployment.id'
Output Structure:
.services.edges[].node - Service info
.node.serviceInstances.edges[].node.latestDeployment.id - Latest deployment UUID
.node.serviceInstances.edges[].node.latestDeployment.meta - Commit info, build config, etc.
Logs
View Logs
railway logs
railway logs --service api
railway logs --environment production
railway logs --deployment
railway logs --build
railway logs <deployment-id>
railway logs --service worker --deployment
railway logs --json
railway logs --service api --deployment --json
Logs Tips:
- Default: Shows latest deployment logs
- Deployment logs: Application startup and runtime output
- Build logs: Compilation, dependencies, Nixpacks output
- Use
--json with jq for filtering
Environment Variables
railway variables
railway variables --service api
railway variables --environment production
railway variables --kv
railway variables --json
railway variables --set "DATABASE_URL=postgres://..."
railway variables --set "NODE_ENV=production" --set "LOG_LEVEL=debug"
railway run npm start
railway shell
Environments
railway environment
railway environment production
railway environment new
railway environment delete <environment-name>
Scaling
railway scale --us-west1 3
railway scale --service api --us-west1 2
railway scale --us-west1 2 --europe-west4 1
Volumes
railway volume list
railway volume list --service api
railway volume add
railway volume delete <volume-id>
railway volume update <volume-id>
railway volume detach <volume-id>
railway volume attach <volume-id>
Database Connection
railway connect
Authentication
railway login
railway logout
railway whoami
Common Workflows
Initial Project Setup
railway login
railway link
railway init
railway service api
railway environment production
railway status
Deploy with Environment Variables
railway variables --set "NODE_ENV=production" --set "API_KEY=secret"
railway up
railway logs --deployment
Debug Failed Deployment
DEPLOY_ID=$(railway status --json | jq -r '.services.edges[0].node.serviceInstances.edges[0].node.latestDeployment.id')
railway logs $DEPLOY_ID --build
railway logs $DEPLOY_ID --deployment
railway status --json | jq '.services.edges[].node.serviceInstances.edges[].node.latestDeployment'
Monitor Multiple Services
railway logs --service api --deployment
railway logs --service worker --deployment
railway logs --service api --json | jq 'select(.level == "error")'
Extract Deployment Information
railway status --json | jq -r '.services.edges[].node | {service: .name, deployment: .serviceInstances.edges[0].node.latestDeployment.id}'
railway status --json | jq -r '.services.edges[].node.serviceInstances.edges[].node.latestDeployment.meta | {commit: .commitHash, message: .commitMessage}'
railway status --json | jq -r '.services.edges[].node | select(.serviceInstances.edges[0].node.latestDeployment.canRedeploy == true)'
Redeploy After Config Change
railway variables --set "NEW_VAR=value"
railway redeploy --yes
railway up
Run Commands with Railway Environment
railway run npm run migrate
railway run node scripts/seed.js
railway run npm run dev
railway shell
Important Notes
Deployment Targets
- Production: Linked to production environment
- Preview: Branch-based deployments (configured in Railway dashboard)
- Development: Local with
railway run or railway shell
JSON Output
railway status --json is the most comprehensive command
- Contains: services, deployment IDs, commit info, build config, service instances
- Use
jq for parsing and filtering
Environment Linking
- Project, service, and environment are all linked separately
- Use
railway status to verify what you're linked to
- Change with
railway service, railway environment, railway link
Logs Behavior
- Default: Latest deployment logs (5-minute window)
- Deployment logs: Application output (stdout/stderr)
- Build logs: Nixpacks, dependencies, compilation
- JSON output: Structured logs for parsing
Railway.json Configuration
- Stored in project root
- Defines build/deploy configuration per service
- Example:
{
"$schema": "https://railway.app/railway.schema.json",
"build": {
"builder": "NIXPACKS",
"buildCommand": "pnpm install && pnpm run build"
},
"deploy": {
"startCommand": "node dist/index.js",
"healthcheckPath": "/health",
"healthcheckTimeout": 100,
"restartPolicyType": "ON_FAILURE",
"restartPolicyMaxRetries": 10
}
}
Common Issues
- No TTY errors: Command requires interactive input (use JSON output or flags)
- Service not linked: Run
railway service <service-name> first
- Environment not linked: Run
railway environment <env-name> first
- Deployment not found: Use
railway status --json to verify deployment ID exists
Examples from Real Projects
Saturn Backend (API + Worker)
railway status --json | jq '.services.edges[] | {
service: .node.name,
deployment: .node.serviceInstances.edges[0].node.latestDeployment.id,
commit: .node.serviceInstances.edges[0].node.latestDeployment.meta.commitHash
}'
railway logs --service api --deployment
railway logs --service worker --deployment
railway redeploy --service api --yes
railway redeploy --service worker --yes
Debug Production Issue
railway logs --service api --deployment --json | jq 'select(.level == "error" or .level == "fatal")'
railway status --json | jq '.services.edges[] | select(.node.name == "api") | .node.serviceInstances.edges[0].node.latestDeployment.meta'
railway status --json | jq '.services.edges[].node.serviceInstances.edges[].node.latestDeployment.meta.fileServiceManifest.deploy'