I am using node-Mongodb-native drivers, and I am looking for a way to open a persistent database connection, rather than opening / closing it every 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) {
});
How can I make a db object accessible to any module in my application? Instead of opening a connection for each module separately?
Can this be done using module.exports? Or a global variable?
source
share