### Run TanStack Start locally Source: https://github.com/railwayapp/docs/blob/main/content/guides/tanstack-start.md Install dependencies and start the development server. ```bash cd my-app npm install npm run dev ``` -------------------------------- ### Sidekiq/SolidQueue Start Command Example Source: https://github.com/railwayapp/docs/blob/main/content/guides/rails.md This example demonstrates a typical start command for a worker service like Sidekiq or SolidQueue, often used when configuring services individually in the Railway dashboard or a shared railway.json. ```bash bundle exec sidekiq ``` -------------------------------- ### Install dependencies and start development server Source: https://github.com/railwayapp/docs/blob/main/content/guides/solid.md Commands to install project dependencies and launch the Vite development server locally. ```bash npm install ``` ```bash npm run dev ``` -------------------------------- ### Rails Server Start Command Example Source: https://github.com/railwayapp/docs/blob/main/content/guides/rails.md This example shows a common start command for a Rails web server service, typically configured in the Railway dashboard or a railway.json file when not using a shared start command. ```bash bundle exec rails server ``` -------------------------------- ### Serve SPA with Node.js Source: https://github.com/railwayapp/docs/blob/main/content/guides/spa-routing-configuration.md Install the serve package and configure the start script to enable SPA mode, which automatically handles routing fallbacks. ```bash npm install serve ``` ```json { "scripts": { "start": "serve -s dist -l $PORT" } } ``` -------------------------------- ### Initialize and Run Phoenix Application Source: https://github.com/railwayapp/docs/blob/main/content/guides/phoenix.md Commands to install the Phoenix generator, create a new project, prepare the database, and start the local development server. ```bash mix archive.install hex phx_new mix phx.new helloworld mix ecto.create mix phx.server ``` -------------------------------- ### Example: Deploy a Postgres Database Source: https://github.com/railwayapp/docs/blob/main/content/docs/ai/mcp-server.md Example natural language prompt to deploy a Postgres database using the MCP server. ```text Deploy a Postgres database ``` -------------------------------- ### Install Socket.IO Client Source: https://github.com/railwayapp/docs/blob/main/content/guides/socketio.md Install the client-side library for the frontend application. ```bash npm install socket.io-client ``` -------------------------------- ### Install Railway CLI and Configure Agent Support Source: https://github.com/railwayapp/docs/blob/main/content/docs/agents.md Installs the Railway CLI and sets up agent support, including skills, MCP, and authentication. Use this command for initial setup. ```bash bash <(curl -fsSL cli.new) --agents -y ``` -------------------------------- ### Install Django Source: https://github.com/railwayapp/docs/blob/main/content/guides/django.md Install the Django framework within your activated virtual environment. ```bash python -m pip install django ``` -------------------------------- ### Create a TanStack Start project Source: https://github.com/railwayapp/docs/blob/main/content/guides/tanstack-start.md Initialize a new TanStack Start application using the official scaffolding tool. ```bash npx @tanstack/create-start@latest my-app ``` -------------------------------- ### Install S3 storage adapter Source: https://github.com/railwayapp/docs/blob/main/content/guides/payload-cms.md Install the necessary package to enable S3-compatible storage for media. ```bash npm install @payloadcms/storage-s3 ``` -------------------------------- ### Configure Node.js/Next.js to listen on all interfaces Source: https://github.com/railwayapp/docs/blob/main/content/docs/private-networking.md This example shows how to configure a Node.js Next.js application to listen on all network interfaces (IPv4 and IPv6). It covers updating the start command or configuring a custom server with the hostname set to '::'. This ensures compatibility with different network environments. ```bash next start --hostname :: --port ${PORT-3000} ``` ```javascript const port = process.env.PORT || 3000; const app = next({ // ... hostname: "::", port: port, }); ``` -------------------------------- ### Install Dependencies for React App Source: https://github.com/railwayapp/docs/blob/main/content/guides/react.md Navigate into your project directory and run this command to install necessary dependencies. ```bash npm install ``` -------------------------------- ### Example: Deploy a ClickHouse Database Source: https://github.com/railwayapp/docs/blob/main/content/docs/ai/mcp-server.md Example natural language prompt to deploy a single-node ClickHouse database using the MCP server. ```text Deploy a single node ClickHouse database ``` -------------------------------- ### Start Local Development with Verbose Output Source: https://github.com/railwayapp/docs/blob/main/content/docs/cli/dev.md Starts local development services and displays verbose domain replacement information. Useful for debugging. ```bash railway dev --verbose ``` -------------------------------- ### Researcher Agent Start Command Source: https://github.com/railwayapp/docs/blob/main/content/guides/multi-agent-system.md Use this start command to deploy the researcher agent. Ensure all necessary environment variables are set. ```bash python -m agents.researcher ``` -------------------------------- ### Example: Create and Deploy Next.js App Source: https://github.com/railwayapp/docs/blob/main/content/docs/ai/mcp-server.md This is an example natural language prompt to create a Next.js app, deploy it to Railway, and assign a domain. ```text Create a Next.js app in this directory and deploy it to Railway. Also assign it a domain. ``` -------------------------------- ### Install and Use Railway CLI Source: https://github.com/railwayapp/docs/blob/main/content/guides/vibe-coding-deploy.md Install the Railway CLI globally, log in to your account, initialize a new project, and deploy your code. ```bash npm install -g @railway/cli railway login railway init railway up ``` -------------------------------- ### Install Production Dependencies Source: https://github.com/railwayapp/docs/blob/main/content/guides/django.md Install Gunicorn for serving, Whitenoise for static files, and Psycopg for PostgreSQL database connection. ```bash python -m pip install gunicorn whitenoise psycopg[binary,pool] ``` -------------------------------- ### Example: Pull Environment Variables Source: https://github.com/railwayapp/docs/blob/main/content/docs/ai/mcp-server.md Example natural language prompt to pull environment variables for a project and save them to a .env file. ```text Pull environment variables for my project and save them to a .env file ``` -------------------------------- ### Start Local Development Source: https://github.com/railwayapp/docs/blob/main/content/docs/cli/dev.md Starts image-based services via Docker Compose and prompts for code service configuration. Use this to begin local development. ```bash railway dev ``` -------------------------------- ### Check CLI Install Method Source: https://github.com/railwayapp/docs/blob/main/content/docs/cli/upgrade.md Displays the detected installation method and the corresponding upgrade command without performing an actual upgrade. ```bash railway upgrade --check ``` -------------------------------- ### Writer Agent Start Command Source: https://github.com/railwayapp/docs/blob/main/content/guides/multi-agent-system.md Use this start command for the writer agent. A staggered startup delay is recommended to avoid API rate limits. ```bash python -m agents.writer ``` -------------------------------- ### Start Local MCP Server Source: https://github.com/railwayapp/docs/blob/main/content/docs/cli/mcp.md Run this command with no subcommand to start the local stdio MCP server. This is used by local MCP client configurations. ```bash railway mcp ``` -------------------------------- ### Examples Source: https://github.com/railwayapp/docs/blob/main/content/docs/integrations/api.md A list of example queries and mutations organized by resource type to help users get started with the Railway API. ```APIDOC ## Examples To help you get started, we have provided example queries and mutations organized by resource type: - [API Cookbook](/integrations/api/api-cookbook) - Quick reference for common operations - [Manage Projects](/integrations/api/manage-projects) - Create, update, delete projects - [Manage Services](/integrations/api/manage-services) - Create services, configure settings - [Manage Deployments](/integrations/api/manage-deployments) - Deploy, rollback, view logs - [Manage Variables](/integrations/api/manage-variables) - Set and manage environment variables - [Manage Environments](/integrations/api/manage-environments) - Create and configure environments - [Manage Domains](/integrations/api/manage-domains) - Add custom domains, configure DNS - [Manage Volumes](/integrations/api/manage-volumes) - Create volumes, manage backups ``` -------------------------------- ### Example: Create and Link New Environment Source: https://github.com/railwayapp/docs/blob/main/content/docs/ai/mcp-server.md Example natural language prompt to create a new environment cloned from production, name it 'development', and set it as linked. ```text Create a development environment called `development` cloned from production and set it as linked ``` -------------------------------- ### Initialize and Run Development Server Source: https://github.com/railwayapp/docs/blob/main/README.md Commands to install project dependencies and launch the local development server. Requires Node.js and pnpm to be installed on the host machine. ```bash pnpm install pnpm dev ``` -------------------------------- ### Create and Run a Basic Flask App Source: https://github.com/railwayapp/docs/blob/main/content/guides/flask.md This snippet demonstrates how to create a simple Flask application, including setting up a project directory, virtual environment, installing Flask, and running the app locally. It also shows how to prepare the app for deployment by installing gunicorn and freezing dependencies into requirements.txt. ```bash mkdir flaskproject cd flaskproject python -m venv env source env/bin/activate python -m pip install flask ``` ```python import os from flask import Flask app = Flask(__name__) @app.route('/') def hello(): return 'Hello world, welcome to Railway!' ``` ```bash flask --app helloworld run ``` ```bash pip install gunicorn gunicorn main:app ``` ```bash pip freeze > requirements.txt ``` -------------------------------- ### Service-Specific Start Commands for Railway Source: https://github.com/railwayapp/docs/blob/main/content/guides/rails.md These are examples of service-specific start commands that should be set in the Railway dashboard. They define how different types of services (web, Sidekiq worker, SolidQueue worker) are initiated from the same codebase. ```bash bin/rails server -b :: ``` ```bash bundle exec sidekiq ``` ```bash bin/jobs ``` -------------------------------- ### Add Prisma and Initialize Schema Source: https://github.com/railwayapp/docs/blob/main/content/guides/fullstack-nextjs.md Install Prisma and its client, then initialize Prisma in your project. This sets up the necessary tools for database schema management and interaction. ```bash npm install prisma @prisma/client npx prisma init ``` -------------------------------- ### Example Dockerfile for Node.js Source: https://github.com/railwayapp/docs/blob/main/content/guides/vibe-coding-deploy.md A generic Dockerfile for a Node.js application on Railway. It installs dependencies, builds the project, and exposes the application port. ```dockerfile FROM node:20-alpine WORKDIR /app COPY package*.json ./ RUN npm ci COPY . . RUN npm run build EXPOSE ${PORT} CMD ["npm", "start"] ``` -------------------------------- ### Run Next.js Locally Source: https://github.com/railwayapp/docs/blob/main/content/guides/nextjs.md Navigate to the project directory and start the development server. ```bash cd helloworld npm run dev ``` -------------------------------- ### Create and Configure Beego App Source: https://github.com/railwayapp/docs/blob/main/content/guides/beego.md This snippet demonstrates creating a new Beego application, installing dependencies, configuring a PostgreSQL database connection, defining a Users model, and seeding the database with initial data. It also shows how to prepare the app for deployment by reading the database URL from environment variables. ```bash bee new helloworld cd helloworld go mod tidy go get github.com/lib/pq ``` ```go package main import ( "fmt" _ "helloworld/routers" _ "github.com/lib/pq" "github.com/beego/beego/v2/client/orm" beego "github.com/beego/beego/v2/server/web" "log" ) // Users - type Users struct { ID int `orm:"column(id)"` FirstName string `orm:"column(first_name)"` LastName string `orm:"column(last_name)"` } func init() { // set default database orm.RegisterDriver("postgres", orm.DRPostgres) // set default database dbURL, err := beego.AppConfig.String("db_url") if err != nil { log.Fatal("Error getting database URL: ", err) } orm.RegisterDataBase("default", "postgres", dbURL) // register model orm.RegisterModel(new(Users)) // create table orm.RunSyncdb("default", false, true) } func main() { o := orm.NewOrm() // Create a slice of Users to insert users := []Users{ {FirstName: "John", LastName: "Doe"}, {FirstName: "Jane", LastName: "Doe"}, {FirstName: "Railway", LastName: "Deploy Beego"}, } // Iterate over the slice and insert each user for _, user := range users { id, err := o.Insert(&user) if err != nil { fmt.Printf("Failed to insert user %s %s: %v\n", user.FirstName, user.LastName, err) } else { fmt.Printf("Inserted user ID: %d, Name: %s %s\n", id, user.FirstName, user.LastName) } } beego.Run() } ``` ```ini db_url = ${DATABASE_URL} ``` -------------------------------- ### Dockerfile for Astro App Source: https://github.com/railwayapp/docs/blob/main/content/guides/astro.md This Dockerfile uses the Node alpine image to build and serve an Astro application. It installs dependencies, builds the app, and starts the server. ```docker # Use the Node alpine official image # https://hub.docker.com/_/node FROM node:lts-alpine # Create and change to the app directory. WORKDIR /app # Copy the files to the container image COPY package*.json ./ # Install packages RUN npm ci # Copy local code to the container image. COPY . ./ # Build the app. RUN npm run build # Serve the app CMD ["npm", "run", "start"] ``` -------------------------------- ### Initialize Node.js Project Source: https://github.com/railwayapp/docs/blob/main/content/guides/socketio.md Install the required Express and Socket.IO dependencies for the server. ```bash npm init -y npm install express socket.io ``` -------------------------------- ### Set Up Agent Support for Existing Railway CLI Source: https://github.com/railwayapp/docs/blob/main/content/docs/agents.md Configures agent support for an already installed Railway CLI. This command handles skills, MCP, and authentication setup. ```bash railway setup agent ``` -------------------------------- ### Initialize Node.js Project Source: https://github.com/railwayapp/docs/blob/main/content/guides/deploy-ai-saas.md Set up the project directory and install necessary dependencies for an Express-based AI application. ```bash mkdir ai-saas && cd ai-saas npm init -y npm install express openai pg ``` -------------------------------- ### Define Dockerfile for FastAPI Deployment Source: https://github.com/railwayapp/docs/blob/main/content/guides/fastapi.md A standard Dockerfile configuration to containerize a FastAPI application. It uses a lightweight Python alpine image, installs dependencies from requirements.txt, and starts the application using the Hypercorn server. ```dockerfile FROM python:3-alpine WORKDIR /app COPY . . RUN pip install --no-cache-dir -r requirements.txt CMD ["hypercorn", "main:app", "--bind", "::"] ``` -------------------------------- ### Get Latest Deployment ID using JSON Output Source: https://github.com/railwayapp/docs/blob/main/content/docs/cli/deployment.md A scripting example that retrieves the ID of the very latest deployment by combining JSON output with the `jq` tool. This is useful for automating tasks that depend on the most recent deployment. ```bash # Get the latest deployment ID railway deployment list --json --limit 1 | jq -r '.[0].id' ``` -------------------------------- ### Create a Dockerfile for NestJS Source: https://github.com/railwayapp/docs/blob/main/content/guides/nest.md This Dockerfile uses the official Node.js LTS image to containerize a NestJS application. It sets the working directory, copies the source code, installs dependencies using npm ci, and defines the command to start the production server. ```dockerfile FROM node:lts WORKDIR /app COPY . ./ RUN npm ci CMD ["npm", "run", "start:prod"] ``` -------------------------------- ### Get Current User Info (CLI) Source: https://github.com/railwayapp/docs/blob/main/content/docs/cli/whoami.md Retrieves information about the currently logged-in user via the Railway CLI. It can output basic user details or a comprehensive JSON object with workspace information. No external dependencies are required beyond the Railway CLI installation. ```bash railway whoami ``` ```bash railway whoami --json ``` -------------------------------- ### Make HTTP request to internal service using internal hostname Source: https://github.com/railwayapp/docs/blob/main/content/docs/private-networking.md This JavaScript example shows how to make an HTTP GET request to another service within the Railway private network. It uses the internal DNS name of the target service (e.g., 'api.railway.internal') and the service's port (e.g., 3000) to construct the URL. ```javascript app.get("/fetch-secret", async (req, res) => { axios.get("http://api.railway.internal:3000/secret").then(response => { res.json(response.data); }); }); ``` -------------------------------- ### Initialize MCP Server Project Source: https://github.com/railwayapp/docs/blob/main/content/guides/mcp-server.md Commands to set up the project directory, install necessary dependencies, and initialize TypeScript configuration. ```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 ``` -------------------------------- ### Run Server Locally Source: https://github.com/railwayapp/docs/blob/main/content/guides/mcp-server.md Command to build and start the server for local testing. ```bash npm run build && npm start ``` -------------------------------- ### Install BullMQ Dependencies Source: https://github.com/railwayapp/docs/blob/main/content/guides/fullstack-nextjs.md Installs the necessary packages for background job processing. ```bash npm install bullmq ioredis ``` -------------------------------- ### Create a new Strapi project Source: https://github.com/railwayapp/docs/blob/main/content/guides/strapi.md Use this command to initialize a new Strapi project. Select Postgres as the database during the setup process. ```bash npx create-strapi@latest my-strapi-app ``` -------------------------------- ### Get a service instance Source: https://github.com/railwayapp/docs/blob/main/content/docs/integrations/api/manage-services.md Get detailed service configuration for a specific environment. ```APIDOC ## Get a service instance Get detailed service configuration for a specific environment: ``` -------------------------------- ### Create Next.js App and Install AI SDK Source: https://github.com/railwayapp/docs/blob/main/content/guides/ai-chatbot-streaming.md Use create-next-app to scaffold a new Next.js project 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 --typescript cd my-chatbot npm install ai @ai-sdk/openai @ai-sdk/react ``` -------------------------------- ### Start and Manage Distillery Release Source: https://github.com/railwayapp/docs/blob/main/content/guides/phoenix-distillery.md Provides commands to start, manage, and interact with a built Distillery release. Includes options for starting a console, running in the foreground or background, and connecting to a running release. ```bash > _build/prod/rel/helloworld_distillery/bin/helloworld_distillery console ``` ```bash > _build/prod/rel/helloworld_distillery/bin/helloworld_distillery foreground ``` ```bash > _build/prod/rel/helloworld_distillery/bin/helloworld_distillery start ``` ```bash > _build/prod/rel/helloworld_distillery/bin/helloworld_distillery remote_console ``` ```bash > _build/prod/rel/helloworld_distillery/bin/helloworld_distillery attach ``` ```bash > _build/prod/rel/helloworld_distillery/bin/helloworld_distillery help ``` -------------------------------- ### Create a Project Source: https://github.com/railwayapp/docs/blob/main/content/docs/integrations/api/api-cookbook.md Create a new project with a specified name. Optional fields allow for description, workspace assignment, and configuration of deploy environments. ```graphql mutation projectCreate($input: ProjectCreateInput!) { projectCreate(input: $input) { id } } ``` -------------------------------- ### Dockerfile for TanStack Start Source: https://github.com/railwayapp/docs/blob/main/content/guides/tanstack-start.md A multi-stage Dockerfile to build and run the TanStack Start application. ```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"] ``` -------------------------------- ### Install Redis adapter dependencies Source: https://github.com/railwayapp/docs/blob/main/content/guides/socketio.md Install the required packages to enable Redis-based message routing. ```bash npm install @socket.io/redis-adapter redis ``` -------------------------------- ### Define Build Scripts Source: https://github.com/railwayapp/docs/blob/main/content/guides/mcp-server.md Add these scripts to package.json to enable building and starting the server. ```json { "scripts": { "build": "tsc", "start": "node dist/index.js" } } ``` -------------------------------- ### Get Volume Instance Details Source: https://github.com/railwayapp/docs/blob/main/content/docs/integrations/api/manage-volumes.md Get details about a specific volume instance within an environment. ```APIDOC ## Get volume instance details ### Description Get details about a volume instance (volume in a specific environment). ### Method GET ### Endpoint /graphql ### Query Parameters - **id** (String!) - Required - The ID of the volume instance. ### Request Example ```json { "query": "query volumeInstance($id: String!) {\n volumeInstance(id: $id) {\n id\n mountPath\n currentSizeMB\n state\n volume {\n id\n name\n }\n serviceInstance {\n serviceName\n }\n }\n}", "variables": { "id": "volume-instance-id" } } ``` ### Response #### Success Response (200) - **volumeInstance.id** (String) - The ID of the volume instance. - **volumeInstance.mountPath** (String) - The path where the volume is mounted. - **volumeInstance.currentSizeMB** (Int) - The current size of the volume in MB. - **volumeInstance.state** (String) - The current state of the volume instance. - **volumeInstance.volume.id** (String) - The ID of the associated volume. - **volumeInstance.volume.name** (String) - The name of the associated volume. - **volumeInstance.serviceInstance.serviceName** (String) - The name of the service instance. #### Response Example ```json { "data": { "volumeInstance": { "id": "volume-instance-id", "mountPath": "/data", "currentSizeMB": 1024, "state": "ATTACHED", "volume": { "id": "volume-id", "name": "my-volume" }, "serviceInstance": { "serviceName": "my-service" } } } } ``` ``` -------------------------------- ### Run Astro development server Source: https://github.com/railwayapp/docs/blob/main/content/guides/astro.md Starts the local development server for testing the application. ```bash npm run dev ``` -------------------------------- ### Install Railway CLI with Scoop Source: https://github.com/railwayapp/docs/blob/main/content/docs/cli.md Installs the Railway CLI on Windows using the Scoop package manager. ```powershell scoop install railway ``` -------------------------------- ### Shell Wrapper for Environment Variables in Start Command Source: https://github.com/railwayapp/docs/blob/main/content/docs/builds/build-and-start-commands.md Illustrates how to wrap a start command in `/bin/sh -c` to ensure environment variable expansion when deploying from a Dockerfile or image. This is necessary because commands run in exec form do not support variable expansion. ```shell /bin/sh -c "exec python main.py --port $PORT" ``` -------------------------------- ### Install Railway CLI with Homebrew Source: https://github.com/railwayapp/docs/blob/main/content/docs/cli.md Installs the Railway CLI on macOS using the Homebrew package manager. ```bash brew install railway ``` -------------------------------- ### Add start script to package.json Source: https://github.com/railwayapp/docs/blob/main/content/guides/sveltekit.md Add a 'start' script to your `package.json` file to specify how to run the built SvelteKit application. This script is used by deployment platforms. ```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" } } ```