Spaces:
Paused
Paused
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 }; |