0

Hi Basir

Thanks in advance for wonderful course, i am following it and on part20. I am trying to establish a connection with the mongodb but could not. i got the files

.env

MONGODB_URL = mongodb://localhost/ZZZAS
—————————————————–
config.js

import dotenv from \’dotenv\’;
dotenv.config();
export default{
MONGODB_URL: process.env.MONGODB_URL,
};
——————————————————-

i have added below section into the server.js as described in the tutorial

import mongoose from \’mongoose\’;
import config from \’./config\’;
mongoose.connect(config.MONGODB_URL, {
useNewUrlParser: true,
useUnifiedTopology: true,
useCreateIndex: true,
}).then(() => {
console.log(\”Connected to Mongodb.\”);
})
.catch((error) =>{
console.log(error.reason);
});

——————————-
i am still unable to establish a connection with the mongoodb, when i run the npm start at the root folder , instead of the message \”Connected to Mongodb\” i am getting \”undefined\”. would you please guide me where i am making a mistake. The mongodb installation on my system shows (HOST localhost:27017).

A Raja Asked question October 25, 2022