Created
December 11, 2020 05:16
-
-
Save eduardopc/6062a318d24216a88587592f9a6fe4d8 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
import mongoose from 'mongoose'; | |
export default class DatabaseBootstrap { | |
DBURI: string; | |
constructor() { | |
this.DBURI = process.env.DB_CONNECTION_STRING as string; | |
} | |
public async bootstrap(): Promise<void> { | |
try { | |
await mongoose.connect( | |
this.DBURI, | |
{ | |
useNewUrlParser: true, | |
useUnifiedTopology: true, | |
}, | |
); | |
console.error('Database connected successfully'); | |
} catch (err) { | |
console.error('Unable to connect to the database. Error:', err); | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment