Skip to content

Instantly share code, notes, and snippets.

@notsonoobie
Created October 16, 2020 19:58
Show Gist options
  • Save notsonoobie/51cf7269cbe31ae54defc73a5c449118 to your computer and use it in GitHub Desktop.
Save notsonoobie/51cf7269cbe31ae54defc73a5c449118 to your computer and use it in GitHub Desktop.
MongoDB Connection starter template using mongoose.
const mongoose = require('mongoose')
const connectDB = async () => {
try{
await mongoose.connect(process.env.MONGO_URI,{
useNewUrlParser: true,
useUnifiedTopology: true,
useCreateIndex: true,
useFindAndModify: false
})
console.log("MongoDB Connected")
}catch(e){
console.error(e.message)
process.exit(1)
}
}
module.exports = connectDB
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment