Railway unable to connect to linked database
I'm getting the following error when deploying my backend to railway.
It will run locally and connect to the database, but railway is unable to connect. Despite the .env file and the railway variables being the same. My connection string does start with
"mongodb://
so I am unsure of where to start with this error.Solution:Jump to solution
Thanks for the help. I was able to figured out that railway is looking for
MONGO_URL
and my application was using MONGOURL
locally.22 Replies
Project ID:
8e9ef9bf-0cad-446a-a5fe-350cc41f3c87
8e9ef9bf-0cad-446a-a5fe-350cc41f3c87
do some simple debugging, like printing the environment variable
It's printing fine in my routes, however I have noticed that my homepage of
/
is returning
{
"message": "Cannot GET /",
"error": "Not Found",
"statusCode": 404
}
Could this be related?backend's don't typically have home pages? so no I don't see a problem with that
That makes sense, I am new to this.
I have all of my variables set up to be shared, is this the proper way to do this?
All of the values match the local env file
why shared? you only have one service
Nevermind they are service variables. I have deleted all of my shared variables just in case and restarted the deploy but it is the same issue,
^
I am having this same problem https://gyazo.com/76bfb714aa081e9fdb89095cd27b3bf4
Gyazo
Gyazo
Nothing in my code changed today.. it just started crashing
this error wouldn't be an issue with railway, please do some research on this topic, perhaps you are never closing your connections
How can I print what the variables are on railway's end? I am able to print them locally but I need to see what railway is using for the connection string
print what variables specifically?
same as printing locally, just refer to the deployment logs
The mongo_url
I am seeing in the docs that I can use a console.log, but I am not seeing the results of it.
Should I be looking in the build logs?
the deployment logs
but if you aren't seeing a log that may mean the variable is empty as railway trims leading and trailing whitespace and then if the resulting log line is empty nothing makes its way to the deployment logs
so do
console.log("mongo url", process.env.MONGO_URL)
insteadSo i have this log in my main.ts file
And here is the full deploy log. I'm not seeing my log anywhere.
it's crashing long before it gets to the point of starting the server, log that variable right before the database connection attempt, also, please do not use watch mode when on Railway, it can cause massive instabilities
Solution
Thanks for the help. I was able to figured out that railway is looking for
MONGO_URL
and my application was using MONGOURL
locally.awesome