File size: 572 Bytes
81e7811
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
const { MongoClient } = require('mongodb');
require('dotenv').config();

const dbUri = process.env.DB_URI;

if (!dbUri) {
  throw new Error("Missing DB_URI environment variable");
}

const dbName = "AkenoXJs";
const client = new MongoClient(dbUri);

const connectToMongoDB = async () => {
    try {
        await client.connect();
        console.log("Connected to MongoDB");
        const db = client.db(dbName);

        return db;
    } catch (error) {
        console.error("Connection failed:", error.message);
    }
};

module.exports = { client, connectToMongoDB };