Created
December 7, 2020 05:23
-
-
Save kunxin-chor/fcd96a51fccd5ca4fe93b7b2676865e8 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const MongoClient = require("mongodb").MongoClient; | |
// global variable | |
let _db; | |
async function connect(url, dbname) | |
{ | |
let client = await MongoClient.connect(url, { | |
useUnifiedTopology:true | |
}); | |
_db = client.db(dbname) | |
console.log("Database connected"); | |
} | |
function getDB() { | |
return _db; | |
} | |
module.exports = { | |
connect, getDB | |
} | |
/* | |
In JavaScript ES6, the export will be done as: | |
export { connect, getDB } | |
*/ |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment