8 months ago
Railway Support Bug Report: Variable Reference Not Working for Backend Services
Issue Summary
Problem: Database Variable Reference (${{service-name.DATABASE_URL}}) is not resolving correctly for Backend services, while working perfectly for Auth services in the same project.
Impact: Backend services cannot use Variable References and must rely on hardcoded DATABASE_URL, creating maintenance issues and potential security concerns.
Environment Details
•Platform: Railway
•Region: Southeast Asia (Singapore)
•Project: Smart Village Management System
•Database Service: smart-village-database2 (PostgreSQL)
•Affected Services: Backend services (Node.js)
•Working Services: Auth services (Node.js)
Detailed Problem Description
Services Configuration:
1.smart-village-authen-service (
WORKING)
•Uses: ${{smart-village-database2.DATABASE_URL}}
•Status: Variable Reference resolves correctly
•Connection: Successful
2.smart-village-backend (
NOT WORKING)
•Uses: ${{smart-village-database2.DATABASE_URL}}
•Status: Variable Reference does not resolve
•Error: ECONNREFUSED / TypeError: Cannot read properties of undefined
Error Details:
Plain Text
TypeError: Cannot read properties of undefined (reading 'searchParams') at parse (/app/node_modules/pg-connection-string/index.js:39:30)
Troubleshooting Attempts:
1.Recreated Backend Service - Same issue persists
2.Verified Service Linking - Database appears linked in Railway dashboard
3.Checked Railway Provided Variables - No DATABASE_URL available for Backend
4.Tested with Hardcoded URL - Works perfectly with direct URL
Evidence
Working Auth Service Variables:
•DATABASE_URL: ${{smart-village-database2.DATABASE_URL}}
Resolves correctly
•Service connects to database successfully
Non-Working Backend Service Variables:
•DATABASE_URL: ${{smart-village-database2.DATABASE_URL}}
Does not resolve
•Railway Provided Variables: No DATABASE_URL present
•Must use hardcoded URL: postgresql://postgres:wTSCdmYKIEipsSiVQhbWvZqfVQIQkrUL@switchback.proxy.rlwy.net:45960/railway
Expected Behavior
Variable Reference ${{smart-village-database2.DATABASE_URL}} should resolve to the actual database URL for ALL services in the project, not just Auth services.
Current Workaround
Using hardcoded DATABASE_URL in Backend services, which works but defeats the purpose of Variable References and creates maintenance overhead.
Request
Please investigate why Variable References work for some services but not others in the same project, and provide a fix to ensure consistent behavior across all services.
Additional Information
•Both services use identical Node.js runtime
•Both services are in the same Railway project
•Database service is healthy and accessible
•Issue is reproducible across multiple Backend service instances
Thank you for your assistance in resolving this issue.
4 Replies
8 months ago
Quick question here are you using a docker file for your services?
Status changed to Awaiting User Response Railway • 8 months ago
8 months ago
Yes, I am using a Dockerfile for my services (both smart-village-backend and smart-village-authen-service).
Status changed to Awaiting Railway Response Railway • 8 months ago
8 months ago
Please remove your hardcoded url string to the database and change it
8 months ago
If you need to use a variable during build, you would need to explicitly reference it in your Dockerfile -
https://docs.railway.com/guides/dockerfiles#using-variables-at-build-time
Note, This is only something you need to do for variables you need access to during the build portion, during runtime all variables are available automatically.