-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathdb.js
32 lines (25 loc) · 797 Bytes
/
db.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
// db.js - A module for connecting to MongoDB
require("dotenv").config();
const { MongoClient } = require("mongodb");
let dbConnection;
module.exports = {
connectToServer: async function (callback) {
try {
console.log("Connecting to MongoDB...");
console.log(process.env.MONGODB_URI);
const client = await MongoClient.connect(process.env.MONGODB_URI, {
useNewUrlParser: true,
useUnifiedTopology: true,
});
dbConnection = client.db('WoWTokenData');
console.log('Successfully connected to MongoDB.');
return callback();
} catch (err) {
console.error("Connection error: ", err);
return callback(err);
}
},
getDb: function () {
return dbConnection;
}
};