title: Design pattern for shared database handle in Node.JS
body: <p>How do I share a database connection across various NodeJS modules? The example I have found all had a monolithic structure where the entire code was in one single app.js file. </p>
  
  <pre><code>/* main.js */
  var foo = require("./foo"); 
  /* express stuff ...*/
  mysql = /* establish mysql connection */ 
  app.get("/foo", foo.hello ); 
  
  
  /* foo.js */
  exports.hello = function(req, res) {
     res.send("Hello from the foo module!"); 
  }
  </code></pre>
  
  <p>How would I access "mysql" from my module "foo"? What is the recommended design pattern for this?  </p>