Skip to content Skip to sidebar Skip to footer

Send Error Msg To Ejs File In Nodejs

i have a register form and i need to send the error message when username exist or email exist: nodejs code : app.post('/register', function(req, res) { var entity = _.pick(req

Solution 1:

You can Print the data passed from server side part to ejs using

<%=%>

for example: <%=user%> will print user.

When err object exsists send it as third object to the ejs file and read it in the same way.

if(err){
res.render('register', {user : undefined, success :true,successs :true,error: err});
}

and in the View

<%if(typeof error == "undefined"){%>
        //Show some HTML here
 <% } else { %>
         //Show other html when you send error obejct sent
         <%= error.message%> //For Example
    <%}%>

Post a Comment for "Send Error Msg To Ejs File In Nodejs"