Skip to content

Instantly share code, notes, and snippets.

@joepie91
Created February 17, 2015 16:48
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save joepie91/a8270b0b7a1a433032a2 to your computer and use it in GitHub Desktop.
Save joepie91/a8270b0b7a1a433032a2 to your computer and use it in GitHub Desktop.
Making things available globally in Express
db = getDatabaseConnectionSomehow();
app.use(function(req, res, next){
req.db = db;
next();
});
// [...]
app.get("/", function(req, res) {
// req.db now contains the database connection
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment