Skip to content

Instantly share code, notes, and snippets.

@eduardopc
Created December 11, 2020 05:16
Show Gist options
  • Save eduardopc/6062a318d24216a88587592f9a6fe4d8 to your computer and use it in GitHub Desktop.
Save eduardopc/6062a318d24216a88587592f9a6fe4d8 to your computer and use it in GitHub Desktop.
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