Monday, 22 May 2017

EJS Helper function moongose

recently I faced the problem that the result from database is not as not be able to display on the page. What am I doing wrong ?

This is the function code which is located in index.js

res.locals.get_user_name = function () {
    User.findOne({_id: 2}).exec().then(function (user) {
        return user.name;
    });
};

And this is a code template EJS

<div class="name"><% get_user_name() %></div>



via DefaultX

No comments:

Post a Comment