text: const mongoose = require('mongoose');
  const util = require('util');
  
  // config should be imported before importing any other file
  const config = require('./config');
  
  const debug = require('debug')('hl7-telescoper-api-server:index');
  
  // connect to mongo db
  const mongoUri = config.mongo.host;
  mongoose.connect(mongoUri, { keepAlive: 1, useNewUrlParser: true });
  mongoose.connection.on('error', () => {
    throw new Error(`unable to connect to database: ${mongoUri}`);
  });
  
  // print mongoose logs in dev env
  if (config.mongooseDebug) {
    mongoose.set('debug', (collectionName, method, query, doc) => {
      debug(`${collectionName}.${method}`, util.inspect(query, false, 20), doc);
    });
  }
  
  module.exports = mongoose;
  