import { Db , MongoClient } from 'mongodb' ; const connStr = 'mongodb://localhost:27017' ; const dbName = "inversify-express-example" ; export class MongoDBConnection { private static isConnected : boolean = false ; private static db : Db ; public static getConnection ( result ) { if ( this . isConnected ) { return result ( this . db ) ; } else { this . connect ( ( error , db ) => { return result ( this . db ) ; } ) ; } } private static connect ( result ) { MongoClient . connect ( connStr , ( err , client ) => { this . db = client . db ( dbName ) ; this . isConnected = true ; return result ( err , this . db ) ; } ) ; } }