I found another way of doing this, and I think it has some advantages.
- Don't polute your code exporting filters.
- Access any method without the need to export them all.
- Better ejs usage (no | pipes).
On your controller, or view.js do this:
var moment = require('moment');
exports.index = function(req, res) {
// send moment to your ejs
res.render('index', { moment: moment });
}
Now you can use moment inside your ejs:
<html>
<h1><%= moment().fromNow() %></h1>
</html>
I'm not an Node expert, so if anyone see something bad on doing this, let me know! :)
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…