| name | railway |
| description | Deploy applications on Railway platform. Use when deploying containerized apps, setting up databases, configuring private networking, or managing Railway projects. Triggers on Railway, railway.app, deploy container, Railway database. |
Railway Deployment
Deploy and manage applications on Railway's platform.
Quick Start
npm i -g @railway/cli
railway login
railway init
railway up
railway.toml Configuration
[build]
builder = "nixpacks"
buildCommand = "npm run build"
[deploy]
startCommand = "npm start"
healthcheckPath = "/health"
healthcheckTimeout = 300
restartPolicyType = "on_failure"
restartPolicyMaxRetries = 3
[service]
internalPort = 3000
Nixpacks Configuration
[phases.setup]
nixPkgs = ["nodejs-18_x", "python311"]
[phases.install]
cmds = ["npm ci"]
[phases.build]
cmds = ["npm run build"]
[start]
cmd = "npm start"
Environment Variables
railway variables set DATABASE_URL="postgres://..."
railway variables set < .env
railway service
railway variables set API_KEY="secret"
Database Services
PostgreSQL
railway add -d postgres
railway variables get DATABASE_URL
Redis
railway add -d redis
MySQL
railway add -d mysql
Private Networking
DATABASE_HOST: ${{postgres.railway.internal}}
DATABASE_PORT: 5432
Volumes (Persistent Storage)
railway volume create my-data
railway volume attach my-data:/app/data
In code:
const dataPath = '/app/data';
fs.writeFileSync(`${dataPath}/file.json`, JSON.stringify(data));
Cron Jobs
[deploy]
startCommand = "node cron.js"
cronSchedule = "0 */6 * * *"
Multi-Service Setup
my-project/
├── api/
│ ├── railway.toml
│ └── ...
├── worker/
│ ├── railway.toml
│ └── ...
└── frontend/
├── railway.toml
└── ...
Deploy each:
cd api && railway up
cd ../worker && railway up
cd ../frontend && railway up
Dockerfile Deploy
FROM node:18-alpine
WORKDIR /app
COPY package*.json ./
RUN npm ci --only=production
COPY . .
EXPOSE 3000
CMD ["npm", "start"]
[build]
builder = "dockerfile"
dockerfilePath = "./Dockerfile"
Health Checks
app.get('/health', (req, res) => {
res.status(200).json({
status: 'healthy',
timestamp: new Date().toISOString()
});
});
[deploy]
healthcheckPath = "/health"
healthcheckTimeout = 100
Resources