To use MomentJS in views/custom.ejs, what is the correct way (if any)?
Server side
routes/index etc we can easily use require(\'moment\');
I found another way of doing this, and I think it has some advantages.
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:
<%= moment().fromNow() %>
I'm not an Node expert, so if anyone see something bad on doing this, let me know! :)