### Run TanStack Start App Locally Source: https://docs.railway.com/guides/tanstack-start Navigate to your project directory, install dependencies, and start the development server. Access the app at http://localhost:3000. ```bash cd my-app npm install npm run dev ``` -------------------------------- ### Install Stripe CLI and Projects Plugin Source: https://docs.railway.com/integrations/stripe Install the Stripe CLI and the projects plugin to get started with Stripe provisioning. ```bash stripe plugin install projects stripe projects init ``` -------------------------------- ### Create React App Start Command Source: https://docs.railway.com/deployments/troubleshooting/no-start-command-could-be-found Serve static site files for a Create React App project. Similar to Vite, this uses the `serve` command (install with `npm install serve`). The `--listen $PORT` flag directs it to the correct port, and `build` indicates the output directory. ```bash serve --single --listen $PORT build ``` -------------------------------- ### Install serve package Source: https://docs.railway.com/guides/spa-routing-configuration Install the 'serve' package to enable Node-based serving for SPAs. This is a simple setup for less complex deployments. ```bash npm install serve ``` -------------------------------- ### Quick Start: Create, Execute, and Destroy Sandbox Source: https://docs.railway.com/sandboxes A basic example demonstrating how to create a sandbox, execute a simple command, and then destroy the sandbox. It reads credentials from environment variables. ```typescript import { Sandbox } from "railway"; // reads RAILWAY_API_TOKEN + RAILWAY_ENVIRONMENT_ID from the environment const sandbox = await Sandbox.create(); const { stdout } = await sandbox.exec("echo hello"); console.log(stdout); await sandbox.destroy(); ``` -------------------------------- ### MCP Installation Guide for Editors Source: https://docs.railway.com/ai/mcp-server Provides configuration details for integrating MCP into editors, with options for local stdio and remote HTTP configurations. This guide helps in manual setup or understanding the `railway mcp install` command. ```bash ``` -------------------------------- ### Install Prisma and Initialize Project Source: https://docs.railway.com/guides/fullstack-nextjs Install Prisma and its client, then initialize Prisma in your project. ```bash npm install prisma @prisma/client npx prisma init ``` -------------------------------- ### Vite Start Command Source: https://docs.railway.com/deployments/troubleshooting/no-start-command-could-be-found Serve static site files for a Vite project. The `serve` command, which can be installed via `npm install serve`, is used here. The `--listen $PORT` flag ensures it listens on the correct port, and `dist` specifies the build output directory. ```bash serve --single --listen $PORT dist ``` -------------------------------- ### Define Start Command Source: https://docs.railway.com/config-as-code/reference Specify the command to run when the container starts. Can be set to `null`. ```json { "$schema": "https://railway.com/railway.schema.json", "deploy": { "startCommand": "node index.js" } } ``` -------------------------------- ### Install Flask Source: https://docs.railway.com/guides/flask Install the Flask framework within your activated virtual environment. ```bash python -m pip install flask ``` -------------------------------- ### Create Next.js App and Install AI SDK Source: https://docs.railway.com/guides/ai-chatbot-streaming Use this command to create a new Next.js application and install the necessary AI SDK packages. For Anthropic, install `@ai-sdk/anthropic` instead of `@ai-sdk/openai`. ```bash npx create-next-app@latest my-chatbot --app --typescriptcd my-chatbotnpm install ai @ai-sdk/openai @ai-sdk/react ``` -------------------------------- ### Install Supabase Client Source: https://docs.railway.com/guides/frontend-authentication Install the Supabase JavaScript client library using npm. ```bash npm install @supabase/supabase-js ``` -------------------------------- ### Install Project Dependencies Source: https://docs.railway.com/guides/luminus Run this command after updating `project.clj` to download and install new dependencies, such as the `cheshire` library. ```bash lein deps ``` -------------------------------- ### Service with Build and Start Commands Source: https://docs.railway.com/infrastructure-as-code/reference Configures a service with explicit build and start commands. ```typescript const web = service("web", { build: "pnpm build", start: "pnpm start", }); ``` -------------------------------- ### Install Django Source: https://docs.railway.com/guides/django Install the Django framework within your activated virtual environment. This command fetches and installs the latest stable version of Django. ```bash python -m pip install django ``` -------------------------------- ### Clone Example Project Source: https://docs.railway.com/guides/bridge-railway-to-rds-with-tailscale Clone the provided Terraform example project to set up AWS resources for RDS and Tailscale connectivity. ```bash git clone git@github.com:echohack/rds-tailscale.git ``` -------------------------------- ### Start Release in Console Source: https://docs.railway.com/guides/phoenix-distillery Command to start the built release in an interactive console, similar to `iex -S mix`. ```bash _build/prod/rel/helloworld_distillery/bin/helloworld_distillery console ``` -------------------------------- ### Install Session Auth Dependencies Source: https://docs.railway.com/guides/frontend-authentication Install necessary packages for session-based authentication with Express and Postgres. ```bash npm install express express-session connect-pg-simple bcrypt ``` -------------------------------- ### Check CLI Install Method Source: https://docs.railway.com/cli/upgrade Displays the detected installation method and the corresponding upgrade command without performing an update. ```bash railway upgrade --check ``` ```text Install method: Homebrew Binary path: /opt/homebrew/bin/railway Upgrade command: brew upgrade railway ``` -------------------------------- ### Install Railway TypeScript SDK Source: https://docs.railway.com/sandboxes Install the Railway SDK using Bun. This is the first step to programmatically interact with Railway resources. ```bash bun add railway ``` -------------------------------- ### Sign Up/In and Deploy with Auto-Accept Source: https://docs.railway.com/cli/up Signs you in (creating an account if needed), then creates a project from the current directory and deploys it, skipping prompts. Recommended for automated or scripted first runs. ```bash railway up -y ``` -------------------------------- ### Fork a Running Sandbox Source: https://docs.railway.com/sandboxes Create a new, independent sandbox by cloning the filesystem of a running sandbox. The fork starts from a copy of the disk, preserving files but not running processes or memory. This is ideal for branching after expensive setup like dependency installation. ```typescript const base = await Sandbox.create(); await base.exec("npm install"); const fork = await base.fork(); await fork.exec("npm test"); // sees the installed dependencies, isolated from base ``` -------------------------------- ### Initialize Project and Install Dependencies Source: https://docs.railway.com/guides/mcp-server Sets up a new project directory, initializes npm, and installs the MCP SDK along with development dependencies for TypeScript. ```bash mkdir my-mcp-server && cd my-mcp-server npm init -y npm install @modelcontextprotocol/sdk express npm install -D typescript @types/node @types/express npx tsc --init ``` -------------------------------- ### Equivalent Configuration Definitions Source: https://docs.railway.com/guides/config-as-code These examples demonstrate how to define build and deploy settings in both TOML and JSON formats. ```toml [build] builder = "railpack" buildCommand = "echo building!" [deploy] preDeployCommand = ["npm run db:migrate"] startCommand = "echo starting!" healthcheckPath = "/" healthcheckTimeout = 100 restartPolicyType = "never" ``` ```json { "build": { "builder": "railpack", "buildCommand": "echo building!" }, "deploy": { "preDeployCommand": ["npm run db:migrate"], "startCommand": "echo starting!", "healthcheckPath": "/", "healthcheckTimeout": 100, "restartPolicyType": "never" } } ``` -------------------------------- ### Configure Railway Agent and AI Tools Source: https://docs.railway.com/cli Set up the Railway agent tooling and install AI coding tools using the `railway setup agent` and `railway mcp install` commands. You can also install specific agent skills. ```bash railway setup agent # Configure Railway agent tooling ``` ```bash railway mcp install # Configure MCP for AI coding tools ``` ```bash railway skills install # Install Railway agent skills ``` -------------------------------- ### Dockerfile for TanStack Start Deployment Source: https://docs.railway.com/guides/tanstack-start A Dockerfile to build and deploy a TanStack Start application on Railway. It installs dependencies, builds the app, and specifies the server entry point. ```dockerfile FROM node:lts-alpine AS build WORKDIR /app COPY package*.json ./ RUN npm ci COPY . ./ RUN npm run build FROM node:lts-alpine WORKDIR /app COPY --from=build /app/.output ./.output COPY --from=build /app/package*.json ./ EXPOSE 3000 CMD ["node", ".output/server/index.mjs"] ``` -------------------------------- ### Build and Start Local Server Source: https://docs.railway.com/guides/mcp-server Build the project and start the local server for testing. The server typically runs on port 3000. ```bash npm run build && npm start ``` -------------------------------- ### Initialize a project Source: https://docs.railway.com/cli/init Basic command to initialize a new project. ```bash railway init [OPTIONS] ``` -------------------------------- ### Get current user in JSON format Source: https://docs.railway.com/cli/whoami Use the `--json` flag to get detailed user information in JSON format, which is useful for scripting or programmatic access. Ensure you have the Railway CLI installed. ```bash railway whoami --json ``` -------------------------------- ### GraphQL Query Example Source: https://docs.railway.com/integrations/api/graphql-overview Use queries to read data from the API. This is the GraphQL equivalent of a GET request. ```graphql query { me { id name email } } ``` -------------------------------- ### Set up AI SaaS Project Source: https://docs.railway.com/guides/deploy-ai-saas Initializes a new project directory and installs necessary dependencies for an Express.js application with OpenAI and PostgreSQL integration. ```bash mkdir ai-saas && cd ai-saas npm init -y npm install express openai pg ``` -------------------------------- ### Dockerfile with Custom Playwright Setup Source: https://docs.railway.com/guides/playwright Manually install Playwright and its dependencies on a standard Node.js image if you need more control over the base image or only require a specific browser. The --with-deps flag installs both the browser binary and system libraries. ```docker FROM node:20-bookworm # Install only Chromium and its system dependencies RUN npx playwright install --with-deps chromium WORKDIR /app COPY package*.json ./ RUN npm ci COPY . ./ ENTRYPOINT ["node", "index.js"] ``` -------------------------------- ### Add start script for serve Source: https://docs.railway.com/guides/spa-routing-configuration Configure the 'start' script in your package.json to use the 'serve' command with SPA mode enabled. The '-s' flag ensures all requests are rewritten to index.html. ```json { "scripts": { "start": "serve -s dist -l $PORT" } } ``` -------------------------------- ### Create a New Sails App Source: https://docs.railway.com/guides/sails Generate a new Sails.js application. You will be prompted to select a template, and after installation, you can start the app locally. ```bash sails new workapp ``` -------------------------------- ### Create project with specific name Source: https://docs.railway.com/cli/init Initializes a project with a predefined name. ```bash railway init --name my-api ``` -------------------------------- ### Dockerfile for Fastify Application Source: https://docs.railway.com/guides/fastify This Dockerfile sets up a Node.js 18 environment, copies the application code, installs dependencies, and defines the command to start the web service. ```dockerfile # Use the Node.js 18 alpine official image # https://hub.docker.com/_/node FROM node:18-alpine # Create and change to the app directory. WORKDIR /app # Copy local code to the container image. COPY . . # Install project dependencies RUN npm ci # Run the web service on container startup. CMD ["npm", "start"] ``` -------------------------------- ### Initialize Node.js Project Source: https://docs.railway.com/guides/deploy-node-express-api-with-auto-scaling-secrets-and-zero-downtime Create a new directory and initialize a package.json file. ```bash mkdir my-express-apicd my-express-apinpm init -y ``` -------------------------------- ### Migrate Service Configuration from JSON to TypeScript Source: https://docs.railway.com/infrastructure-as-code Translate settings from `railway.json` to the `.railway/railway.ts` DSL. This example shows converting `build`, `start`, and `healthcheckPath` settings for a service. ```json { "build": { "buildCommand": "pnpm build" }, "deploy": { "startCommand": "pnpm start", "healthcheckPath": "/health" } } ``` ```typescript const web = service("web", { build: "pnpm build", start: "pnpm start", healthcheck: "/health", }); ``` -------------------------------- ### Create a new Strapi project Source: https://docs.railway.com/guides/strapi Use this command to initialize a new Strapi application. Select Postgres as the database during setup and push the project to a GitHub repository. ```bash npx create-strapi@latest my-strapi-app ``` -------------------------------- ### Run Axum App Locally Source: https://docs.railway.com/guides/axum Execute this command in your project's root directory to build and run your Axum application locally. This will install dependencies and start the server. ```bash cargo run ``` -------------------------------- ### Get custom domain status Source: https://docs.railway.com/integrations/api/manage-domains Retrieve the current status of a custom domain, including its verification token and DNS record configuration. This is useful for monitoring the domain's setup progress. ```GraphQL query customDomain($id: String!, $projectId: String!) { customDomain(id: $id, projectId: $projectId) { id domain status { verificationToken dnsRecords { hostlabel requiredValue currentValue status } certificateStatus } } } ``` -------------------------------- ### Dockerfile for NestJS App Source: https://docs.railway.com/guides/nest This Dockerfile uses the official Node.js LTS image, sets the working directory, copies the application code, installs dependencies using npm ci, and defines the command to start the application in production mode. ```bash # Use the Node official image # https://hub.docker.com/_/node FROM node:lts # Create and change to the app directory. WORKDIR /app # Copy local code to the container image COPY . ./ # Install packages RUN npm ci # Serve the app CMD ["npm", "run", "start:prod"] ``` -------------------------------- ### Basic Deploy Source: https://docs.railway.com/cli/up Compresses and uploads the current directory, then streams build and deployment logs. Use this for a standard deployment. ```bash railway up ``` -------------------------------- ### Set Custom Start Command for App Service Source: https://docs.railway.com/guides/symfony Use this custom start command for the App Service to ensure the application starts correctly. ```bash chmod +x ./run-app.sh && sh ./run-app.sh ``` -------------------------------- ### Railway Start Command for Distillery Source: https://docs.railway.com/guides/phoenix-distillery Configure this as the start command in Railway for applications using Distillery. It sets up the database and then starts the release in the foreground. ```bash mix ecto.setup && _build/prod/rel/helloworld_distillery/bin/helloworld_distillery foreground ``` -------------------------------- ### Node.js Start Command Source: https://docs.railway.com/deployments/troubleshooting/no-start-command-could-be-found Use this command to start a Node.js application. Replace `main.js` with your application's entry point file (e.g., `index.js`, `server.js`, `app.js`). ```bash node main.js ``` -------------------------------- ### Add Start Script to package.json Source: https://docs.railway.com/guides/sveltekit Include a 'start' script in your package.json file to specify how to run the built SvelteKit application. This script is essential for deployment. ```json { "name": "svelteapp", "version": "0.0.1", "type": "module", "scripts": { "dev": "vite dev", "build": "vite build", "start": "node build/index.js", "preview": "vite preview", "check": "svelte-kit sync && svelte-check --tsconfig ./tsconfig.json", "check:watch": "svelte-kit sync && svelte-check --tsconfig ./tsconfig.json --watch", "format": "prettier --write .", "lint": "prettier --check . && eslint ." }, "devDependencies": { "@fontsource/fira-mono": "^5.0.0", "@neoconfetti/svelte": "^2.0.0", "@sveltejs/adapter-auto": "^3.0.0", "@sveltejs/adapter-node": "^5.2.9", "@sveltejs/kit": "^2.0.0", "@sveltejs/vite-plugin-svelte": "^4.0.0", "@types/eslint": "^9.6.0", "autoprefixer": "^10.4.20", "eslint": "^9.7.0", "eslint-config-prettier": "^9.1.0", "eslint-plugin-svelte": "^2.36.0", "globals": "^15.0.0", "prettier": "^3.3.2", "prettier-plugin-svelte": "^3.2.6", "prettier-plugin-tailwindcss": "^0.6.5", "svelte": "^5.0.0", "svelte-check": "^4.0.0", "tailwindcss": "^3.4.9", "typescript": "^5.0.0", "typescript-eslint": "^8.0.0", "vite": "^5.0.3" } } ``` -------------------------------- ### Install Phoenix App Generator Source: https://docs.railway.com/guides/phoenix Installs the Phoenix application generator using the mix archive command. Ensure Elixir and Hex are installed first. ```bash mix archive.install hex phx_new ``` -------------------------------- ### Initialize Git and Push to GitHub Source: https://docs.railway.com/platform/migrate-from-replit Use these commands to initialize a new Git repository, add your project files, commit them, and push to a remote GitHub repository. Ensure you remove Replit-specific configuration files before pushing. ```bash cd your-project git init git add . git commit -m "Initial commit" git remote add origin https://github.com/your-username/your-repo.git git branch -M main git push -u origin main ``` -------------------------------- ### Install Dependencies Source: https://docs.railway.com/guides/deploy-node-express-api-with-auto-scaling-secrets-and-zero-downtime Install Express, dotenv, and TypeScript development dependencies. ```bash npm install express dotenvnpm install -D typescript @types/node @types/express tsx ``` -------------------------------- ### Get latest active deployment Source: https://docs.railway.com/integrations/api/manage-deployments Get the currently running deployment. ```APIDOC ## Get latest active deployment ### Description Get the currently running deployment. ### Method GET ### Endpoint /graphql ### Query ```graphql query latestDeployment($input: DeploymentListInput!) { deployments(input: $input, first: 1) { edges { node { id status url createdAt } } } } ``` ### Variables ```json { "input": { "projectId": "project-id", "serviceId": "service-id", "environmentId": "environment-id", "status": { "successfulOnly": true } } } ``` ``` -------------------------------- ### Example Docker Compose File Source: https://docs.railway.com/guides/docker-compose This is a sample docker-compose.yml file demonstrating a web service, a PostgreSQL database, and a Redis cache. ```yaml services: web: build: . ports: - "3000:3000" environment: - DATABASE_URL=postgres://user:pass@db:5432/myapp - REDIS_URL=redis://cache:6379 depends_on: - db - cache db: image: postgres:16 environment: - POSTGRES_DB=myapp - POSTGRES_USER=user - POSTGRES_PASSWORD=pass volumes: - pgdata:/var/lib/postgresql/data cache: image: redis:7-alpine volumes: pgdata: ``` -------------------------------- ### Deploy to a New Project Source: https://docs.railway.com/cli/up Creates a brand-new project and service from the current directory and deploys it, even if the directory is already linked to another project. Use `--name` to specify the project name. ```bash railway up --new --name my-api ``` -------------------------------- ### Install Socket.IO Client Dependency Source: https://docs.railway.com/guides/socketio Install the Socket.IO client library for your frontend application. ```bash npm install socket.io-client ``` -------------------------------- ### Install Express and Socket.IO Dependencies Source: https://docs.railway.com/guides/socketio Install the necessary packages for your Node.js Socket.IO server. ```bash npm init -y npm install express socket.io ``` -------------------------------- ### Create a TanStack Start App Source: https://docs.railway.com/guides/tanstack-start Use npx to create a new TanStack Start project. Follow the prompts to configure your application. ```bash npx @tanstack/create-start@latest my-app ``` -------------------------------- ### Install Express App Dependencies Source: https://docs.railway.com/guides/express Install all necessary packages for your Express application after generating it. ```bash npm install ``` -------------------------------- ### Configure Start Command for SIGTERM Handling Source: https://docs.railway.com/deployments/troubleshooting/nodejs-sigterm-handling Replace the package manager start command with a direct node execution to ensure the application receives termination signals. ```bash npm run start ``` ```bash node index.js ``` -------------------------------- ### Create Source Directory Source: https://docs.railway.com/guides/deploy-node-express-api-with-auto-scaling-secrets-and-zero-downtime Create the source directory for the application code. ```bash mkdir src ``` -------------------------------- ### Create and Activate Virtual Environment Source: https://docs.railway.com/guides/flask Set up a Python virtual environment for your project and activate it. For Windows, use `env\Scripts\activate`. ```bash python -m venv env source env/bin/activate ``` -------------------------------- ### Set Luminus Start Command on Railway Source: https://docs.railway.com/guides/luminus Configure the start command in your Railway service settings to first run database migrations and then start the application. This command dynamically finds the application JAR file. ```bash java -jar $(find ./target -name '*.jar' ! -name '*SNAPSHOT*') migrate && java -jar $(find ./target -name '*.jar' ! -name '*SNAPSHOT*') ``` -------------------------------- ### Quick overview of the linked service Source: https://docs.railway.com/cli/metrics Run this command to get a quick overview of metrics for the currently linked service. ```bash railway metrics ``` -------------------------------- ### Install Clerk SDK for Next.js Source: https://docs.railway.com/guides/frontend-authentication Use npm to install the Clerk SDK for Next.js applications. ```bash npm install @clerk/nextjs ``` -------------------------------- ### Install CloudFront CDK Packages Source: https://docs.railway.com/guides/add-a-cdn-using-cloudfront Installs necessary AWS CDK packages for CloudFront and its origins. ```plaintext npm install @aws-cdk/aws-cloudfront @aws-cdk aws-cloudfront-origins @aws-cdk/core ``` -------------------------------- ### Install Fastify and Etag Plugin Source: https://docs.railway.com/guides/add-a-cdn-using-cloudfront Install Fastify and the @fastify/etag plugin using npm. This is required for setting up the server and handling ETags. ```plaintext npm init -y npm i fastify @fastify/etag ``` -------------------------------- ### Create a New SolidJS App from Template Source: https://docs.railway.com/guides/solid Use this command to scaffold a new SolidJS project from a JavaScript template. Ensure Node.js is installed. ```bash npx degit solidjs/templates/js solidjsapp ``` -------------------------------- ### Get rendered variables for deployment Source: https://docs.railway.com/integrations/api/manage-variables Get all variables as they would appear during a deployment, with all references resolved. ```APIDOC ## Get rendered variables for deployment ### Description Get all variables as they would appear during a deployment, with all references resolved. ### Method Query ### Endpoint variablesForServiceDeployment ### Parameters #### Query Parameters - **projectId** (String!) - Required - The ID of the project. - **environmentId** (String!) - Required - The ID of the environment. - **serviceId** (String!) - Required - The ID of the service. ### Response #### Success Response (200) - **data.variablesForServiceDeployment** (Object) - An object containing key-value pairs of all resolved environment variables for the specified service and environment. ### Response Example ```json { "data": { "variablesForServiceDeployment": { "DATABASE_URL": "postgres://...", "NODE_ENV": "production" } } } ``` ``` -------------------------------- ### Show Project Overview Source: https://docs.railway.com/cli/status Displays the default project overview, including workspace, project, environment, linked service, and grouped resources. ```bash railway status ```