node.jsmongodbdeploymentweb-deploymenteconnrefused

MongooseServerSelectionError: connect ECONNREFUSED 0.0.0.0:27017


So I wanted to try making like a blog website with Node js and MongoDB. I’m a beginner with it so it’s kinda a mess, but everything worked fine locally (on localhost 3000). I found Railway as a free alternative to Heroku and tried to deploy my project there.

For some reason it failed to connect to the database, and this is what I got in the logs.

Here is a small piece of code from app.js

What could be the problem? I will share more code if it is needed.


Solution

  • Had the same problem solved it its really simple 1.Start a mongodb service with railway you will have a new test database 2.Use the mongodb link provided with railway to connect to your new test database add this to your .env DB_URL it will now reflect your given mongodb link 3.commit the changes made to your .env DB_URL 4.Push the new changes to your github and it will now work