MongoDB Database connection failed to my express backend project

I am using ArchCraft. Recently I installed MongoDB on my OS and when I type show dbs it gives me the exact result. But when I run my backend project using npm start it says database connection failed. Then I check my MongoDB Compass but there was not any database created.


//database connection
  .connect(process.env.DATABASE_URL, {
    useNewUrlParser: true,
    useUnifiedTopology: true,
  .then(() => {
    console.log("Database Connection Successfull");
  .catch(() => {
    console.log("Database Connection Failed");

here is my database connection source code. here I am using dotenv. In this file I write this code DATABASE_URL = mongodb://localhost:27017/MEVN_STACK, When I use Ubuntu it works perfectly but now it isn’t working. Please help me to find out the reason.

Are default file permissions different between Ubuntu and Arch? Maybe you don’t have create permissions under Arch.

1 Like

I solved this problem recently. Replacing localhost by is works for me. Can you please explain to me what’s the difference between localhost and

If requests are only accepted at localhost, the server must be able to process requests on on. However, if no specific interface is specified, i.e. is used, then the server listens on all interfaces, which means it may be something like or or something else. means pretty much, it’ll accept a request on any interface.

1 Like