Created
February 18, 2022 10:25
-
-
Save yvesbou/60f3a4bbee7e5577153ae1b21b7e4b16 to your computer and use it in GitHub Desktop.
This file contains hidden or 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
require('dotenv').config(); | |
const mongoose = require('mongoose'); | |
const DATABASE_URL = process.env.DATABASE_URL; | |
const connectDB = () => { | |
return mongoose.connect(DATABASE_URL, {useUnifiedTopology: true, useNewUrlParser: true}, err => { | |
if (err){ | |
console.error('Connection to DB failed'); | |
} else{ | |
console.log('Connection to DB was successful'); | |
} | |
}) | |
} | |
const db = mongoose.connection; | |
db.on('error', console.error.bind(console, "MongoDB connection failed")); | |
module.exports = connectDB; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment