Created
October 16, 2020 19:58
-
-
Save notsonoobie/51cf7269cbe31ae54defc73a5c449118 to your computer and use it in GitHub Desktop.
MongoDB Connection starter template using mongoose.
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 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