Created
February 17, 2015 16:48
-
-
Save joepie91/a8270b0b7a1a433032a2 to your computer and use it in GitHub Desktop.
Making things available globally in Express
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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