title: Best way to share database connection param with mongoose/node.js
body: <p>I'm using <a href="http://mongoosejs.com/" rel="noreferrer">Mongoose</a> to manage a Mongo database. My connection file is quite simple:</p>
  
  <pre><code>var mongoose = require('mongoose')
  
  mongoose.connection.on("open", function(){
    console.log("Connection opened to mongodb at %s", config.db.uri)
  });
  console.log("Connecting to %s", config.db.uri)
  mongoose.connect(config.db.uri)
  
  global.mongoose = mongoose
  </code></pre>
  
  <p>Then in my app.js I just</p>
  
  <pre><code>require('./database)
  </code></pre>
  
  <p>and the "mongoose" variable is available globally. I'd prefer not to use globals (at least not directly). Is there a better way of sharing the database connection variable across node (I'm using express.js) via a singleton pattern or some other method?</p>