[{"data":1,"prerenderedAt":335},["ShallowReactive",2],{"blog-how-to/railway-env-vars":3},{"id":4,"title":5,"body":6,"category":316,"date":317,"dateModified":317,"description":318,"draft":319,"extension":320,"faq":321,"featured":319,"headerVariant":322,"image":321,"keywords":321,"meta":323,"navigation":324,"ogDescription":325,"ogTitle":321,"path":326,"readTime":321,"schemaOrg":327,"schemaType":328,"seo":329,"sitemap":330,"stem":331,"tags":332,"twitterCard":333,"__hash__":334},"blog/blog/how-to/railway-env-vars.md","How to Set Up Railway Environment Variables",{"type":7,"value":8,"toc":298},"minimark",[9,13,17,21,32,37,57,67,82,119,129,133,137,144,150,154,157,163,167,170,189,195,199,205,209,215,231,261,279],[10,11],"category-badge",{"category":12},"How-To Guide",[14,15,5],"h1",{"id":16},"how-to-set-up-railway-environment-variables",[18,19,20],"p",{},"Manage secrets and configuration in Railway",[22,23,24],"tldr",{},[18,25,26,27,31],{},"TL;DR:\nClick your service in Railway, go to the Variables tab, and add key-value pairs. Railway automatically redeploys when you save. Use variable references (\n$",[28,29],"binding",{"value":30},"SERVICE.VAR","\n) to share values between services. Use Shared Variables for project-wide secrets.",[33,34,36],"h2",{"id":35},"step-by-step-setup","Step-by-Step Setup",[38,39,41,46],"step",{"number":40},"1",[42,43,45],"h3",{"id":44},"open-your-project","Open your project",[18,47,48,49,56],{},"Go to ",[50,51,55],"a",{"href":52,"rel":53},"https://railway.app/dashboard",[54],"nofollow","railway.app/dashboard"," and click on your project.",[38,58,60,64],{"number":59},"2",[42,61,63],{"id":62},"select-your-service","Select your service",[18,65,66],{},"Click on the service you want to configure (e.g., your web app, API, or database).",[38,68,70,74],{"number":69},"3",[42,71,73],{"id":72},"navigate-to-variables","Navigate to Variables",[18,75,76,77,81],{},"Click the ",[78,79,80],"strong",{},"Variables"," tab in the service panel.",[38,83,85,89,92,108],{"number":84},"4",[42,86,88],{"id":87},"add-variables","Add variables",[18,90,91],{},"You have two options:",[93,94,95,102],"ul",{},[96,97,98,101],"li",{},[78,99,100],{},"Add individually:"," Click \"New Variable\" and enter key/value",[96,103,104,107],{},[78,105,106],{},"Raw Editor:"," Click \"RAW Editor\" to paste multiple variables at once",[109,110,115],"pre",{"className":111,"code":113,"language":114},[112],"language-text","# In Raw Editor, paste like a .env file:\nDATABASE_URL=postgresql://...\nSTRIPE_SECRET_KEY=sk_test_xxxxx\nOPENAI_API_KEY=sk-xxxxx\n","text",[116,117,113],"code",{"__ignoreMap":118},"",[38,120,122,126],{"number":121},"5",[42,123,125],{"id":124},"save-and-deploy","Save and deploy",[18,127,128],{},"Railway automatically triggers a redeploy when you save variables. You'll see the deployment start in the Deployments tab.",[33,130,132],{"id":131},"railway-specific-features","Railway-Specific Features",[42,134,136],{"id":135},"variable-references","Variable References",[18,138,139,140,143],{},"Railway lets you reference variables from other services using the ",[116,141,142],{},"${{SERVICE.VAR}}"," syntax:",[109,145,148],{"className":146,"code":147,"language":114},[112],"# Reference the database URL from your Postgres service\nDATABASE_URL=${{Postgres.DATABASE_URL}}\n\n# Reference another service's variable\nAPI_URL=${{api.RAILWAY_PUBLIC_DOMAIN}}\n",[116,149,147],{"__ignoreMap":118},[42,151,153],{"id":152},"built-in-railway-variables","Built-in Railway Variables",[18,155,156],{},"Railway provides several built-in variables automatically:",[109,158,161],{"className":159,"code":160,"language":114},[112],"# Available in every service\nRAILWAY_ENVIRONMENT=production\nRAILWAY_PUBLIC_DOMAIN=your-app.up.railway.app\nRAILWAY_PRIVATE_DOMAIN=your-app.railway.internal\nRAILWAY_PROJECT_ID=xxx\nRAILWAY_SERVICE_ID=xxx\n",[116,162,160],{"__ignoreMap":118},[42,164,166],{"id":165},"shared-variables","Shared Variables",[18,168,169],{},"For variables needed across multiple services:",[171,172,173,176,183],"ol",{},[96,174,175],{},"Click on \"Shared Variables\" at the project level",[96,177,178,179,182],{},"Add your variable (e.g., ",[116,180,181],{},"STRIPE_SECRET_KEY",")",[96,184,185,186],{},"In each service, reference it: ",[116,187,188],{},"STRIPE_SECRET_KEY=${{shared.STRIPE_SECRET_KEY}}",[190,191,192],"tip-box",{},[18,193,194],{},"Pro tip:\nUse Shared Variables for API keys that multiple services need. This way you only update the key in one place when rotating.",[33,196,198],{"id":197},"using-the-railway-cli","Using the Railway CLI",[109,200,203],{"className":201,"code":202,"language":114},[112],"# Link to your project\nrailway link\n\n# List variables for current service\nrailway variables\n\n# Add a variable\nrailway variables set STRIPE_SECRET_KEY=sk_test_xxxxx\n\n# Get a specific variable\nrailway variables get DATABASE_URL\n\n# Delete a variable\nrailway variables delete OLD_KEY\n\n# Run local dev with Railway variables\nrailway run npm run dev\n",[116,204,202],{"__ignoreMap":118},[33,206,208],{"id":207},"common-variable-patterns","Common Variable Patterns",[109,210,213],{"className":211,"code":212,"language":114},[112],"# Database (auto-populated when adding Railway Postgres)\nDATABASE_URL=${{Postgres.DATABASE_URL}}\n\n# Redis (auto-populated when adding Railway Redis)\nREDIS_URL=${{Redis.REDIS_URL}}\n\n# Internal service communication\nAPI_INTERNAL_URL=http://${{api.RAILWAY_PRIVATE_DOMAIN}}:3000\n\n# External URL for webhooks\nWEBHOOK_URL=https://${{RAILWAY_PUBLIC_DOMAIN}}/api/webhook\n\n# Secrets (use Shared Variables)\nSTRIPE_SECRET_KEY=${{shared.STRIPE_SECRET_KEY}}\nOPENAI_API_KEY=${{shared.OPENAI_API_KEY}}\n",[116,214,212],{"__ignoreMap":118},[216,217,218,221],"warning-box",{},[18,219,220],{},"Private vs Public Domains",[18,222,223,226,227,230],{},[116,224,225],{},"RAILWAY_PRIVATE_DOMAIN"," is for internal service-to-service communication (faster, no internet). ",[116,228,229],{},"RAILWAY_PUBLIC_DOMAIN"," is your public URL. Use private domains when services talk to each other within Railway.",[232,233,234,241,255],"faq-section",{},[235,236,238],"faq-item",{"question":237},"Do I need to restart after changing variables?",[18,239,240],{},"No, Railway automatically triggers a new deployment when you save variable changes. The new deployment will have the updated values.",[235,242,244],{"question":243},"How do I use Railway variables locally?",[18,245,246,247,250,251,254],{},"Use ",[116,248,249],{},"railway run"," to run commands with your Railway environment variables. For example: ",[116,252,253],{},"railway run npm run dev",". This injects all your service's variables into the local process.",[235,256,258],{"question":257},"Can I have different variables for staging and production?",[18,259,260],{},"Yes, Railway supports environments. You can create a \"staging\" environment and set different variable values for each environment. Click on \"Environments\" in your project to manage them.",[18,262,263,266,270,271,270,275],{},[78,264,265],{},"Related guides:",[50,267,269],{"href":268},"/blog/how-to/environment-variables","Environment Variables Guide"," ·\n",[50,272,274],{"href":273},"/blog/how-to/vercel-env-vars","Vercel Environment Variables",[50,276,278],{"href":277},"/blog/how-to/hide-api-keys","How to Hide API Keys",[280,281,282,288,293],"related-articles",{},[283,284],"related-card",{"description":285,"href":286,"title":287},"Step-by-step guide to implementing OAuth 2.0 securely. Use PKCE, validate tokens properly, and avoid common OAuth vulner","/blog/how-to/oauth-setup","How to Set Up OAuth Authentication Securely",[283,289],{"description":290,"href":291,"title":292},"Step-by-step guide to using parameterized queries to prevent SQL injection. Examples for PostgreSQL, MySQL, MongoDB, and","/blog/how-to/parameterized-queries","How to Use Parameterized Queries",[283,294],{"description":295,"href":296,"title":297},"Step-by-step guide to implementing secure password reset flows. Prevent account takeover, token attacks, and enumeration","/blog/how-to/password-reset-security","How to Implement Secure Password Reset",{"title":118,"searchDepth":299,"depth":299,"links":300},2,[301,309,314,315],{"id":35,"depth":299,"text":36,"children":302},[303,305,306,307,308],{"id":44,"depth":304,"text":45},3,{"id":62,"depth":304,"text":63},{"id":72,"depth":304,"text":73},{"id":87,"depth":304,"text":88},{"id":124,"depth":304,"text":125},{"id":131,"depth":299,"text":132,"children":310},[311,312,313],{"id":135,"depth":304,"text":136},{"id":152,"depth":304,"text":153},{"id":165,"depth":304,"text":166},{"id":197,"depth":299,"text":198},{"id":207,"depth":299,"text":208},"how-to","2026-01-23","Complete guide to configuring environment variables in Railway. Set up secrets, use variable references, and manage configurations across services.",false,"md",null,"yellow",{},true,"Complete guide to Railway secrets management and configuration.","/blog/how-to/railway-env-vars","[object Object]","HowTo",{"title":5,"description":318},{"loc":326},"blog/how-to/railway-env-vars",[],"summary_large_image","ju9ppyZBPdTu5ZNBgGrXAwjuQYro2ajcb0uLrhuS_yM",1775843927663]