<commit_before>// VARIABLE DECLARATIONS AND CONNECTION STRING
var mongoose = require('mongoose');

// DB CONNECTION STRINGS (DB URI)
// for dev and production environments.
// mLab db info in LastPass
var dbURI = 'mongodb://localhost/"Loc8r';
if (process.env.NODE_ENV === 'production'){
  dbURI = 'mongodb://adam_new_1212:<EMAIL>:19491/heroku_t1hlj430';
  // dbURI = process.env.MONGOLAB_URI;
  // variable holding connection string. obscured in variable to hide db password
}
mongoose.connect(dbURI);
var gracefulShutdown;


// MONITOR MONGOOSE CONNECTION EVENTS
mongoose.connection.on('connected', function() {
  console.log('mongoose connected to ' + dbURI);
});
mongoose.connection.on('error', function(err){
  console.log('mongoose connection error: ' + err);
});
mongoose.connection.on('disconnected', function() {
  console.log('mongoose disconnected.');
});

// HANDLER CLOSES MONGOOSE CONNECTION WHEN APP STOPS
// takes a msg and callback to kill process
gracefulShutdown = function(msg, callback){
  mongoose.connection.close(function(){
    console.log('Mongoose disconnected through: ' + msg);
    callback();
  });
};

// APP STOP EVENT LISTENERS
process.once('SIGUSR2', function () {
  gracefulShutdown('nodemon restart', function() {
    process.kill(process.pid, 'SIGUSR2');
  });
});
process.on('SIGINT', function() {
  gracefulShutdown('app termination', function(){
    process.exit(0);
  });
});
process.on('SIGTERM', function() {
  gracefulShutdown('Heroku app shutdown', function(){
    process.exit(0);
  });
});

// require location Schema
require('./locations.js');



/**
TROUBLESHOOTING CONNECTION FAILURE
i have connection string from db tied to myu heroku acct, arcane app
run heroku config:set cmnd from sidebar instrs DONE. SUCCESS.
ping successsful. port successful. DONE.
http://docs.mlab.com/connecting/#help
we are connectied but we can't restore: (auth failure)

ADD COLLECTION VIA GUI AND QUERY VIA CLI
login, locations add with fields DONE
query... DONE. WORKS.

HEROKU NOT CONNECTING TO MLAB DB
2016-04-26T18:33:01.214825+00:00 app[web.1]: mongoose connection error: MongoError: connect ECONNREFUSED 127.0.0.1:27017

*/<commit_msg>deleted db that heroku couldn't connect to in production env (cloud) and created new one using heroku gui. manually added collection and document on mlab gui and input new mongolab_uri to heroku config vars.we can now run locally with nodemon with cloud db. now I'll push to heroku and test if heroku can connect to mlab db...<commit_after>// VARIABLE DECLARATIONS AND CONNECTION STRING
var mongoose = require('mongoose');

// DB CONNECTION STRINGS (DB URI)
// for dev and production environments.
// mLab db info in LastPass
var dbURI = 'mongodb://localhost/"Loc8r';
if (process.env.NODE_ENV === 'production'){
  dbURI = 'mongodb://adam_new_1212:Loc8rmLabdbpwd<EMAIL>:21741/heroku_n7zpphvz';
  // SETTING USING MONGOLAB_URI DIDN'T WORK....
  // dbURI = process.env.MONGOLAB_URI;
  // connection string. obscured in variable to hide password
}
mongoose.connect(dbURI);
var gracefulShutdown;


// MONITOR MONGOOSE CONNECTION EVENTS
mongoose.connection.on('connected', function() {
  console.log('mongoose connected to ' + dbURI);
});
mongoose.connection.on('error', function(err){
  console.log('mongoose connection error: ' + err);
});
mongoose.connection.on('disconnected', function() {
  console.log('mongoose disconnected.');
});

// HANDLER CLOSES MONGOOSE CONNECTION WHEN APP STOPS
// takes a msg and callback to kill process
gracefulShutdown = function(msg, callback){
  mongoose.connection.close(function(){
    console.log('Mongoose disconnected through: ' + msg);
    callback();
  });
};

// APP STOP EVENT LISTENERS
process.once('SIGUSR2', function () {
  gracefulShutdown('nodemon restart', function() {
    process.kill(process.pid, 'SIGUSR2');
  });
});
process.on('SIGINT', function() {
  gracefulShutdown('app termination', function(){
    process.exit(0);
  });
});
process.on('SIGTERM', function() {
  gracefulShutdown('Heroku app shutdown', function(){
    process.exit(0);
  });
});

// require location Schema
require('./locations.js');



/**



*/
{'fraction_non_alphanumeric': 0.13647342995169082, 'fraction_numerical': 0.016908212560386472, 'mean_word_length': 4.6493860845839015, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 5, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 1, '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': '6682573', 'n_tokens_mistral': 1396, 'n_tokens_neox': 1327, 'n_words': 370}