Metzploreur/data/database.js

23 lines
429 B
JavaScript
Raw Normal View History

2023-11-01 02:00:36 +00:00
const mongodb = require('mongodb');
const MongoClient = mongodb.MongoClient;
let database;
async function connectToDatabase() {
const client = await MongoClient.connect('mongodb://127.0.0.1:27017')
2023-11-01 20:03:07 +00:00
database = client.db('BDE');
2023-11-01 02:00:36 +00:00
}
function getDb() {
if (!database) {
throw { message: 'You must connect first!' };
}
return database;
}
module.exports = {
connectToDatabase: connectToDatabase,
getDb: getDb,
};