Skip to content

Instantly share code, notes, and snippets.

@joepie91
Created April 12, 2015 00:55
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/7f531cc7fa7245e68cc8 to your computer and use it in GitHub Desktop.
Save joepie91/7f531cc7fa7245e68cc8 to your computer and use it in GitHub Desktop.
Configurable middleware in Express.js
// ...
databaseMiddleware = require("./middleware.js");
// ...
app.use(databaseMiddleware("/path/to/database/file.sqlite"));
// ...
module.exports = function databaseMiddleware(path) {
database = sqlite.open(path);
return function(req, res, next) {
req.database = database;
next();
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment