From a76f3ee8d9648d9c5b600498c76d643704b8569f Mon Sep 17 00:00:00 2001 From: Jacquilyn F Date: Sat, 26 Apr 2025 12:53:03 -0500 Subject: [PATCH] added the mongoose conncetions --- server/src/config/connections.ts | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) diff --git a/server/src/config/connections.ts b/server/src/config/connections.ts index e69de29..41ad3cc 100644 --- a/server/src/config/connections.ts +++ b/server/src/config/connections.ts @@ -0,0 +1,19 @@ +import dotenv from 'dotenv'; +dotenv.config(); + +import mongoose from 'mongoose'; + +const MONGODB_URI = process.env.MONGODB_URI || ''; + +const db = async (): Promise => { + try { + await mongoose.connect(MONGODB_URI); + console.log('Database connected.'); + return mongoose.connection; + } catch (error) { + console.error('Database connection error:', error); + throw new Error('Database connection failed.'); + } +}; + +export default db;