Skip to content

Instantly share code, notes, and snippets.

@yann-yinn
Created March 12, 2021 08:22
Show Gist options
  • Save yann-yinn/2901a586bee9e948cd3725a682de03a9 to your computer and use it in GitHub Desktop.
Save yann-yinn/2901a586bee9e948cd3725a682de03a9 to your computer and use it in GitHub Desktop.
connnect do mongoDB
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