MERN database not working

When I clone any MERN project from GitHub and run it locally I am able to run the front-end part and also I am able to connect to the server but I am not able to perform any database operations. What is the right approach to make the database operations work in a MERN project ?

Are you using MongoDB Atlas? And are you allowing Network Access from your servers IP Address. Usually if it works locally but not an a server means you are not giving access to it. If this is the case, I’d recommend you’d check this documentation out: https://www.mongodb.com/docs/atlas/security/ip-access-list/

Hey thanks for your kind reply. And yes I am using MongoDB Atlas and I have checked the option to allow the Network Access from anywhere. Now when I try to start the server I get the following -

1 Like

If you don’t mind, can you send me the link of the GitHub repository you are cloning? I would like to try running this myself for debugging.

Sure… here it is
https://github.com/Magnetic-2021/quiz-app.git

From reading the errors, I think the error has to do with getting the database URL in db/connection.js.

I’m not sure if this will work, but I believe that perhaps removing this:

if (process.env.NODE_ENV === "dev") {
  require("dotenv").config();
}

and replacing it with this:

require("dotenv").config();

might help.

You mean to say I should remove the IF ???

Yes. I think this because you are making a condition, if the .env is in development, configure the env. Maybe for now, change it to just configure .env.