What would be the most appropriate way of sharing the database connection in the below snippet ( the db
variable) with my routers/controllers without turning the
As suggested by @Jed Watson, the moongoose module uses a singleton (anti?) pattern, which is enforced by the require/export mechanism. Here is the specific bit of code :
(as found here : https://github.com/LearnBoost/mongoose/blob/master/lib/index.js)
/*!
* The exports object is an instance of Mongoose.
*
* @api public
*/
var mongoose = module.exports = exports = new Mongoose;