How to reuse mongodb connection in node.js
I'm using node-mongodb-native driver with mongodb to write a website. I have a question about how to open mongodb connection once, then use it in collection name users in user.js and collection name posts in comment.js I want to open db connection in db.js then to insert / save data for users and posts collection Currently code,my db.js var Db = require('mongodb').Db, Connection = require('mongodb').Connection, Server = require('mongodb').Server; module.exports = new Db( 'blog', new Server('localhost', Connection.DEFAULT_PORT, {auto_reconnect: true}) ); I used db.js in user.js as follow var