Railway
Deploy to Railway with one command, with Railway's Postgres and Redis or your own databases.
In a project created with --deploy railway (CLI 0.22.0 or newer), pnpm clubedge deploy uses Railway's CLI and your Railway login:
pnpm clubedge add deploy railway # if the project deploys elsewhere today
pnpm clubedge deployWhat it does
For a full-stack app (Next.js or TanStack Start), deploy:
- Signs in with
railway login, which opens the browser when you are signed out. WithRAILWAY_API_TOKENset, it skips this. - Creates or reuses the Railway project, with Postgres (and Redis with
cache redis) unless your env file points them elsewhere, the app's service named after the package, and a*.up.railway.appdomain. - Sets the production variables it can:
DATABASE_URLandREDIS_URL(references to Railway's databases, or your own URLs),APP_URLandNEXT_PUBLIC_APP_URL,PORT, a generatedBETTER_AUTH_SECRETthat later runs keep,CLIENT_IP_HEADER=x-real-ip, where the client's address is (CLI 0.42.0 or newer), and the env file's values. - Applies
.railway/railway.ts, the service's configuration as code: the migrations before each release and the/api/healthcheck. It writes the file when the project has none and adds Railway's TypeScript SDK (railway) as a dev dependency; commit them. - Uploads the project and waits for Railway's final status: Railway builds the
Dockerfile, runs the migrations, and checks/api/healthbefore switching traffic. Then it prints the URL.
A frontend and its API
CLI 0.35.0 or newer. For a frontend and its API, deploy creates two services instead of one, named after the package and each stack's deployment id:
| Service | App | Domain |
|---|---|---|
<package>-web | The React + Vite frontend, from the root Dockerfile | The public *.up.railway.app domain |
<package>-api | The Hono or FastAPI API, from apps/api/Dockerfile | None: the frontend reaches it over Railway's private network |
- Databases are added as for one app: Postgres, unless your env file points
DATABASE_URLelsewhere. - API variables go on the API service: the database URLs,
FRONTEND_URL(the frontend's public URL),TRUSTED_PROXY_HOPS=1(CLI 0.42.0 or newer), since only the frontend reaches it, and the env file's values other thanVITE_*. - Frontend variables are
PORT,CLIENT_IP_HEADER=x-real-ip(CLI 0.42.0 or newer), and the env file'sVITE_*values, which its build reads. .railway/railway.tsdescribes both services and runs the migrations before each API release.deploywrites it again on each run; when the file has your own configuration,deploystops and asks you to merge the two-service configuration by hand.- It waits for both deployments, then prints the frontend's URL.
deploy --preview deploys one app only, so it refuses on a frontend and its API.
Without a website
CLI 0.44.0 or newer. For a project without a website, deploy creates one service, the API, which the native app calls:
| Service | App | Domain |
|---|---|---|
<package>-api | The Hono or FastAPI API, from apps/api/Dockerfile, on port 3001 | The public *.up.railway.app domain |
- Databases are added as for one app: Postgres (and Redis with
cache redis), unless your env file points them elsewhere. - Variables go on the API: the database URLs,
PORT=3001,CLIENT_IP_HEADER=x-real-ip, since clients reach the API itself, and the env file's values. With Better Auth, which then runs in the API, also a generatedBETTER_AUTH_SECRETthat later runs keep, and the service's public URL asBETTER_AUTH_URL, unless the env file names another public one. .railway/railway.tsdescribes the service and runs the migrations before each release.deploywrites it again on each run, as for a frontend and its API.- It waits for the deployment, then prints the API's URL. Set it as the native app's
EXPO_PUBLIC_API_URLfor its release builds.
deploy --preview refuses here too, and prints how to copy production's environment with Railway's CLI instead.
Railway's CLI
deploy needs Railway CLI 5.42.1 or newer. It uses an installed railway, else one npx already downloaded, and only then downloads one. Installing it once makes deploy faster:
npm install -g @railway/cliCosts
Railway bills the service, Postgres, and Redis by usage on your plan. With your own databases in the env file, Railway only runs the app.
When a deploy fails
deploy names the logs commands: railway logs --build --service <name> for the build, and railway logs --service <name> for the app and its health check. For a frontend and its API, it prints one per service: railway logs --service <package>-web and railway logs --service <package>-api; without a website, the API's. A build that ran out of time (DeadlineExceeded) usually passes on a second try. Fix the cause and run deploy again: it reuses what exists.
To set up Railway without this command, see Railway in the deploy guide.
How is this guide?