diff --git a/backend/config/db.js b/backend/config/db.js index c0076ad..83236cb 100644 --- a/backend/config/db.js +++ b/backend/config/db.js @@ -1,19 +1,22 @@ const mongoose = require("mongoose"); const colors = require("colors"); - const connectDB = async () => { try { + if (!process.env.MONGO_URI) { + throw new Error("MONGO_URI not found in environment variables"); + } const conn = await mongoose.connect(process.env.MONGO_URI, { useNewUrlParser: true, useUnifiedTopology: true, + useCreateIndex: true, + useFindAndModify: false, }); - console.log(`MongoDB Connected: ${conn.connection.host}`.cyan.underline); } catch (error) { console.error(`Error: ${error.message}`.red.bold); - process.exit(1); // Exit with a non-zero status code to indicate an error + process.exit(1); } }; - module.exports = connectDB; +