Created
March 12, 2021 08:22
-
-
Save yann-yinn/2901a586bee9e948cd3725a682de03a9 to your computer and use it in GitHub Desktop.
connnect do mongoDB
This file contains 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"); | |
let db; | |
const client = new MongoClient(process.env.MONGO_URL, { | |
useNewUrlParser: true, | |
useUnifiedTopology: true, | |
}); | |
module.exports = { | |
async connect() { | |
await client.connect(); | |
db = client.db(); | |
console.log("📡 Connected successfully to database " + db.databaseName); | |
}, | |
db: () => db, | |
}; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment