Skip to content

Instantly share code, notes, and snippets.

@electblake
Last active August 30, 2015 15:20
Show Gist options
  • Select an option

  • Save electblake/ed955990d63cd3e36117 to your computer and use it in GitHub Desktop.

Select an option

Save electblake/ed955990d63cd3e36117 to your computer and use it in GitHub Desktop.
/**
* @description similar to domReady but for mongoose.connect
* @example
* require('mongoose-ready')(function(err, readyState) {
* // do stuff if readyState > something good.
* });
*/
var mongoose = require('mongoose'),
cfg = require('./config'),
log = require('./logger');
module.exports = function(cb) {
if (mongoose.connection.readyState) {
cb(null, mongoose.connection.readyState);
} else {
log.debug('Using Mongo', cfg.MONGO_URI);
mongoose.connect(cfg.MONGO_URI, function(err) {
cb(err, mongoose.connection.readyState);
});
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment