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");
require("colors");
//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 ${conn.connection.host}`.bgYellow);
}
catch (error) {
console.log(`Error : ${error.message}`.bgRed);
process.exit(1);
}
};
module.exports = connectDb;
Conclusion
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:
- Crypto-currency website| Source Code Free Download
- How to Build A BMI Calculator in React JS – useState Hook & Conditionals
- How To Create Sign Up Form In HTML and CSS
- Top Stunning Free Websites to Download Responsive HTML Templates 2021
- JavaScript Clock | CSS Neumorphism Working Analog Clock UI Design
- How to make Interactive Feedback Design Using HTML CSS & JS
- 5 amazing ways to earn money online as a side option .
- finest alternative of Chinese apps for Android and iOS
- Top Best 5 Fonts Of 2020 Used By Professional Graphic Designers
- React JS Mini-Project #2 Creating Simple Sum Calculator | Absolute beginners useState Hook & Conditionals