Railway

From G1Joshi/Agent-Skills · View interactive version

Railway is an AI agent skill from the GitHub repository G1Joshi/Agent-Skills. Expert Railway cloud platform assistance covering Nixpacks buildpacks, instant deployments, PostgreSQL/Redis plugins, and environment variables. Use when deploying full-stack web applications without infrastructure overhead.

How to use this skill

Skill file

Railway

Railway is a modern PaaS that offers "Infrastructure from Code". It introspects your repo and deploys it. Can also deploy Databases (Postgres, Redis, Mongo).

When to Use

Quick Start

railway login
railway init
railway up

Core Concepts

Declarative Service Configuration (railway.json)

Defining build commands, health checks, and restart policies:

{
  "$schema": "https://railway.app/railway.schema.json",
  "build": {
    "builder": "NIXPACKS",
    "buildCommand": "npm run build"
  },
  "deploy": {
    "startCommand": "npm start",
    "healthcheckPath": "/healthz",
    "healthcheckTimeout": 100,
    "restartPolicyType": "ON_FAILURE",
    "restartPolicyMaxRetries": 5
  }
}

Private Networking Across Microservices

Connecting internal services securely using Railway private domains:

// Using internal private networking domain (zero public exposure)
const databaseUrl =
  process.env.DATABASE_PRIVATE_URL ||
  "postgresql://postgres:secret@postgres.railway.internal:5432/railway";

const redisUrl =
  process.env.REDIS_PRIVATE_URL ||
  "redis://default:secret@redis.railway.internal:6379";

Railway CLI Workflow

Managing environments and deploying from terminal:

# Log in to Railway account
railway login

# Link local directory to Railway project
railway link

# Run command locally with remote environment variables injected
railway run npm run migrate

# Trigger deployment from local branch
railway up

Common Patterns

Nixpacks Configuration with Custom System Packages

Problem: Applications requiring system packages (e.g. ffmpeg, graphicsmagick) fail to build on standard container buildpacks.

Solution:

Specify custom runtime packages in nixpacks.toml:

[phases.setup]
nixPkgs = ["nodejs-20_x", "ffmpeg", "openssl"]

[phases.build]
cmds = ["npm run build"]

[start]
cmd = "npm start"

Best Practices

Do:

Don't:

Troubleshooting

| Error | Cause | Solution |

| :----------------------------------------------- | :---------------------------------------------------------------------------------- | :---------------------------------------------------------------------------------- |

| Deploy failed: Process did not listen on $PORT | Web service hardcoding port instead of dynamic Railway $PORT. | Bind web server to dynamic port: process.env.PORT \|\| 3000. |

| Database connection timeout in production | Service connecting using public database proxy URL inside the same Railway project. | Use private internal DNS host provided by Railway for zero latency and free egress. |

| Railway CLI: Unauthorized | Project token or user token missing. | Run railway login or export RAILWAY_TOKEN. |

References

Use this skill with your AI agent: Open on Skill Issue to copy, download, or add to your library. Works with Claude, ChatGPT, Gemini, Cursor, Windsurf and more.