import express = require('express'); import mongoose = require('mongoose'); import { config } from '../utils'; export default class Mongo { /** * MongoDB connection in memory; * * @memberof Mongo */ private connection; /** * Connect to MongoDB * * @static * @returns * @memberof Mongo */ public connect(url?: string): any { if (!this.connection) { this.connection = mongoose.createConnection(url || config('database').MONGODB_URL); } return this.connection; } /** * Disconnect from MongoDB * * @static * @memberof Mongo */ public disconnect(callback = () => {}): void { mongoose.connection.close(() => { this.connection = null; callback(); }); } }