<commit_before>'use strict';

// environment variables 
const DB_PORT    = process.env.MONGODB_URI || 'mongodb://localhost/db';

// npm modules 
const debug      = require('debug')('fm:mongooseManager');
const Promise    = require('bluebird');
const mongoose   = require('mongoose');
mongoose.Promise = Promise;



module.exports   = {
  /**  
   * startConnectionToDatabase - Starts the connection to MongoDB  
   *    
   */   
  startConnectionToDatabase() {
    debug(`startConnectionToDatabase, DB_PORT: ${DB_PORT}`);
    return new Promise((resolve, reject) => {
      // Attach event handlers 
      mongoose.connection.on('connected', () => {
        debug('mongoose connection open');
      });
      mongoose.connection.on('disconnected', () => {
        debug('mongoose connection closed');
      });
      mongoose.connection.on('error', (err) => {
        debug('mongoose error \n', err);
      });
      process.on('SIGINT', () => {
        debug('app closing, closing mongoose connection');
        this.closeConnectionToDatabase();
      });
      
      // Connect to MongoDB 
      mongoose.connect(DB_PORT, (err) => {
        if (err) return reject(err);
        return resolve();
      });
    });
  }, 
  
  /**  
   * closeConnectionToDatabase - Closes the connection to MongoDB 
   *    
   * @return {type}  description   
   */   
  closeConnectionToDatabase() {
    debug('closeConnectionToDatabase');
    mongoose.connection.close(() => {
      debug('mongoose connection closed');
    });
  },
};<commit_msg>fixed problem w/ server failing to close<commit_after>'use strict';

// environment variables 
const DB_PORT    = process.env.MONGODB_URI || 'mongodb://localhost/db';

// npm modules 
const debug      = require('debug')('fm:mongooseManager');
const Promise    = require('bluebird');
const mongoose   = require('mongoose');
mongoose.Promise = Promise;



module.exports   = {
  /**  
   * startConnectionToDatabase - Starts the connection to MongoDB  
   *    
   */   
  startConnectionToDatabase() {
    debug(`startConnectionToDatabase, DB_PORT: ${DB_PORT}`);
    return new Promise((resolve, reject) => {
      // Attach event handlers 
      mongoose.connection.on('connected', () => {
        debug('mongoose connection open');
      });
      mongoose.connection.on('disconnected', () => {
        debug('mongoose connection closed');
      });
      mongoose.connection.on('error', (err) => {
        debug('mongoose error \n', err);
      });
      // process.on('SIGINT', () => {
      //   debug('app closing, closing mongoose connection');
      //   this.closeConnectionToDatabase()
      //     .then(() => {
      //       process.exit(0);
      //     })
      //     .catch((err) => {
      //       debug(err);
      //       process.exit(1);
      //     });
      // });
      
      // Connect to MongoDB 
      mongoose.connect(DB_PORT, (err) => {
        if (err) return reject(err);
        return resolve();
      });
    });
  }, 
  
  /**  
   * closeConnectionToDatabase - Closes the connection to MongoDB 
   *    
   * @return {type}  description   
   */   
  closeConnectionToDatabase() {
    return new Promise((resolve, reject) => {
      debug('closeConnectionToDatabase');
      mongoose.connection.close(() => {
        debug('mongoose connection closed');
        return resolve();
      });
    });
  },
};
{'fraction_non_alphanumeric': 0.1547337278106509, 'fraction_numerical': 0.000591715976331361, 'mean_word_length': 2.3574975173783517, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 20, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '7463170', 'n_tokens_mistral': 978, 'n_tokens_neox': 983, 'n_words': 189}