Metzploreur/data/database.js
clement callaert b7d86ef403 video
2023-11-04 13:21:51 +01:00

22 lines
427 B
JavaScript

const mongodb = require('mongodb');
const MongoClient = mongodb.MongoClient;
let database;
async function connectToDatabase() {
const client = await MongoClient.connect('mongodb://0.0.0.0:27017')
database = client.db('BDE');
}
function getDb() {
if (!database) {
throw { message: 'You must connect first!' };
}
return database;
}
module.exports = {
connectToDatabase: connectToDatabase,
getDb: getDb,
};