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;