Skip to content

Instantly share code, notes, and snippets.

@joepie91

joepie91/app.js

Created Apr 12, 2015
Embed
What would you like to do?
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
You can’t perform that action at this time.