// require mongoose
const mongoose = require('mongoose');
// require config file to access mongoURI
const config = require('config');
// make our db the mongoURI
const db = config.get('mongoURI');
const connectDB = async () => {
try {
await mongoose.connect(db, {
useNewUrlParser: true,
useCreateIndex: true,
useUnifiedTopology: true,
useFindAndModify: false
})
console.log('mongo db connected')
} catch (err) {
console.error(err)
//exit with failure
process.exit(1)
}
}
module.exports = connectDB;
Preview:
downloadDownload PNG
downloadDownload JPEG
downloadDownload SVG
Tip: You can change the style, width & colours of the snippet with the inspect tool before clicking Download!
Click to optimize width for Twitter