I am using the node-mongodb-native drivers and I am looking for a way to open a persistent database connection rather than opening/closing it each time.
A simplified connection might look like this...
var DB = new mongo.Db('vows', new mongo.Server("127.0.0.1", 27017, {})),
connection = DB.open(function(err, db) {
// Here we have access to db
});
How can I make the db object accessible to any module in my application? Rather than having to open the connection for every module separately?
Can this be done using module.exports? Or a global variable?