Skip to content

Instantly share code, notes, and snippets.

@lucidstack
Created May 23, 2013 09:21
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 lucidstack/5633916 to your computer and use it in GitHub Desktop.
Save lucidstack/5633916 to your computer and use it in GitHub Desktop.
How to use helpers in Express 3.x
//helpers.js
var moment = require('moment');
var helpers = {
nice_date: function(raw_date) {
return moment(raw_date).format('LL');
}
};
module.exports.load = function(app) {
_.extend(app.locals, helpers);
};
//app.js (MAIN)
var helpers = require('./helpers.js');
var urls = require('./urls.js');
var start_server = function() {
app.set('views', __dirname + '/views');
app.set('view engine', 'jade');
app.use(express.static(__dirname + '/public'));
app.use(express.logger());
helpers.load(app); // <----------
urls.load(app);
app.listen(3000);
};
//and the in any view
p(style='font-family: Droid;') Price: <strong> € #{comic.price} </strong> - <em> #{nice_date(comic.date)} </em>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment