Metzploreur/data/database.js

23 lines
427 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() {
2023-11-04 12:20:07 +00:00
const client = await MongoClient.connect('mongodb://1.0.0.0: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,
};