How to use node modules (like MomentJS) in EJS views?

前端 未结 10 1722
耶瑟儿~
耶瑟儿~ 2020-12-14 00:03

To use MomentJS in views/custom.ejs, what is the correct way (if any)?

  1. Server side

    routes/index etc we can easily use require(\'moment\');

10条回答
  •  隐瞒了意图╮
    2020-12-14 01:00

    var moment = require('moment');
    app.locals.moment = require('moment');
    

    Use in the view:

    <%= moment(myDateValue).fromNow() %>
    

    Now you can simply use moment in your EJS files.

提交回复
热议问题