mirror of
https://github.com/monkeytypegame/monkeytype.git
synced 2024-11-12 10:39:20 +08:00
23 lines
446 B
JavaScript
23 lines
446 B
JavaScript
|
const { MongoClient } = require("mongodb");
|
||
|
|
||
|
let mongoClient;
|
||
|
|
||
|
module.exports = {
|
||
|
async connectDB() {
|
||
|
return MongoClient.connect(process.env.DB_URI, {
|
||
|
useNewUrlParser: true,
|
||
|
useUnifiedTopology: true,
|
||
|
})
|
||
|
.then((client) => {
|
||
|
mongoClient = client;
|
||
|
})
|
||
|
.catch((e) => {
|
||
|
console.log(e);
|
||
|
process.exit(1);
|
||
|
});
|
||
|
},
|
||
|
mongoDB() {
|
||
|
return mongoClient.db(process.env.DB_NAME);
|
||
|
},
|
||
|
};
|