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

前端 未结 10 1714
耶瑟儿~
耶瑟儿~ 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 00:57

    The server side (EJS views) which you mentioned above is running on browser and not on your server. You cannot use require because browsers cannot understand it. You need to import the moment.js to use it

    
    

提交回复
热议问题