Created
March 20, 2021 23:14
-
-
Save loloDawit/fc7c4d8038c18a94e0ff5c2ff3d1a9b2 to your computer and use it in GitHub Desktop.
Database connection
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
| const mongoose = require('mongoose'); | |
| mongoose.Promise = global.Promise; | |
| module.exports = connectDataBase = async () => { | |
| try { | |
| const databaseConnection = await mongoose.connect(process.env.DB, { | |
| useUnifiedTopology: true, | |
| useNewUrlParser: true, | |
| useCreateIndex: true, | |
| }); | |
| console.log(`Database connected ::: ${databaseConnection.connection.host}`); | |
| } catch (error) { | |
| console.error(`Error::: ${error.message}`); | |
| process.exit(1); | |
| } | |
| }; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment