Skip to content

Instantly share code, notes, and snippets.

@dhigginbotham
Created July 3, 2014 19:06
Show Gist options
  • Save dhigginbotham/68f82b6c7b3b2b69cdfa to your computer and use it in GitHub Desktop.
Save dhigginbotham/68f82b6c7b3b2b69cdfa to your computer and use it in GitHub Desktop.
example - share some variables to your templates in express...
//
// Shared Variables Middleware
// ---------------------------
// will get passed to app.locals
//
// Usage:
// app.use(require('./path/to/file'));
//
// require dependencies
var config = require('../../config');
// translation object, probably a good
// idea to keep it flat
var shared = {
brand: config.title,
year: new Date().getFullYear()
};
// middleware fn, express loves simplicity
function vars(req, res, next) {
res.locals.shared = shared;
return next();
}
module.exports = vars;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment