How to connect with database locally with mongo DB | MERN

How to connect with database locally with mongo DB

In this tutorial, we will learn how to connect databases locally with mongo DB . if you want to learn new things in react do comment in the post which post you would like to learn. So without wasting any time let’s start the how to connect with the database locally with mongo DB | MERN.

Let’s start with the first step to connect with mongo DB locally.

First, we have to pass the process file.

const mongoose = require("mongoose");

//connectDB function // this function is basically used to connect with the data base and the make a connection with the data base locaally
const connectDb = async () => {

    try {
    const conn = await mongoose.connect(process.env.MONGO_URI);
    console.log(`MongoDB Connected ${}`.bgYellow);
    catch (error) {
        console.log(`Error : ${error.message}`.bgRed);


module.exports = connectDb;


So there we have it. If you want to easily connect your database do follow these above steps. To learn more about mongo DB and other tutorials do comment on this . Hope you learn a lot from this.

People are also reading:

See also  Blob Maker Step By Step Using HTML, CSS & JavaScript