title: Mongoose connection events with createConnection
body: <p>I moved away from using the default connection to a explicitly defined connection.</p>
  
  <p>My code is working except that none of the event handlers which track the state of my mongo connection are firing.</p>
  
  <p>the events used to fire when I was using default mongoose connection. (mongoose.connect).</p>
  
  <pre><code>var mongoose = require('mongoose'),
      logger = require('../logger'),
      config = require('../config');  
  
  mongoose.connection.on('connecting', function(){
      logger.info("trying to establish a connection to mongo");
  });
  
  mongoose.connection.on('connected', function() {
      logger.info("connection established successfully");
  });
  
  mongoose.connection.on('error', function(err) {
      logger.error('connection to mongo failed ' + err);
  });
  
  mongoose.connection.on('disconnected', function() {
      logger.log('mongo db connection closed');
  })
  
  var gracefulExit = function() {
      db.close(function(){
          logger.log("mongoose connection with db " + server + 'is closing');
          process.exit(0);
      });
  };
  
  process.on('SIGNT', gracefulExit).on('SIGTERM', gracefulExit);
  
  var db = mongoose.createConnection(config.get('DB_URL'));
  module.exports = db;
  </code></pre>
  
  <p>the problem with the code is </p>
  
  <ol>
  <li>None of the event handlers are firing.</li>
  <li>Even the process events on SIGNT and SIGTERM are not firing. </li>
  </ol>
  
  <p>I also tried</p>
  
  <pre><code>var db = mongoose.createConnection(config.get('DB_URL'));
  
  db.on('connecting', function(){
      logger.info("trying to establish a connection to mongo");
  });
  </code></pre>
  
  <p>but this also doesn't fire.</p>