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.
/* 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!");
}
How would I access "mysql" from my module "foo"? What is the recommended design pattern for this?