From 7b13998a28118f06513ec090faf83e7b39d926bc Mon Sep 17 00:00:00 2001 From: Jesus Galaz <jesusgalazr@icloud.com> Date: Sun, 13 Oct 2024 14:16:35 +0200 Subject: [PATCH] Wrong version of this file, fixed with this commit --- mongodb.js | 13 ++++++------- 1 file changed, 6 insertions(+), 7 deletions(-) diff --git a/mongodb.js b/mongodb.js index 783d98c..12594fe 100644 --- a/mongodb.js +++ b/mongodb.js @@ -1,15 +1,14 @@ const mongoose = require('mongoose'); +require('dotenv').config(); -// Function to connect to MongoDB using Mongoose and create collections -async function connectDB() { +const connectDB = async () => { try { - // Connect using the MongoDB URI from environment variables - const conn = await mongoose.connect(process.env.MONGO_URI || "mongodb://127.0.0.1:27017/todo_app"); + const conn = await mongoose.connect(process.env.MONGO_URI); console.log(`MongoDB connected: ${conn.connection.host}`); } catch (err) { console.error(`Error: ${err.message}`); - process.exit(1); // Exit the process with failure if the connection fails + process.exit(1); } -} +}; -module.exports = connectDB; \ No newline at end of file +module.exports = connectDB; -- GitLab