Skip to content

Instantly share code, notes, and snippets.

@Deeks900
Created October 26, 2022 04:36
Show Gist options
  • Save Deeks900/e7f81d07cd5bf73927210ae71f73d8cc to your computer and use it in GitHub Desktop.
Save Deeks900/e7f81d07cd5bf73927210ae71f73d8cc to your computer and use it in GitHub Desktop.
mongo.js
const { MongoClient } = require("mongodb");
const uri = "mongodb://localhost:27017/Bookstore"
let dbConnection;
const getDb = ()=>dbConnection
const connectToDb = async(cb)=>{
MongoClient.connect(uri)
.then((client)=>{
dbConnection = client.db()
console.log("Connection Successful")
return cb();
})
.catch(err=>{
console.log(err);
return cb(err);
})
};
module.exports = {
connectToDb,
getDb
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment