Whats the best view engine for node.js (ejs , jade or handlebars)?

pug is Very awful :nauseated_face::nauseated_face::face_vomiting::face_vomiting::face_vomiting:
specially in large projects , it will become to a big trouble ā€¦
even it donā€™t undrestand svg and when put a svg or xml into your pug file not only it willā€™nt show your svg but it destroy rest of the page code

2 Likes

I think the answer is there is no best.
You have a few options which are worth knowing about and from then you can decide depending on the use case.
Each one is not that hard to learn, so worth investigating each one.

1 Like

Thank you all for sharing your thoughts. From reading the above comments to doing a little research I realized it all comes down to choosing the best option as per your context.

slant.co had some useful comparisions of these templating engines on its website. I have learnt little ejs and believe that its good for me at work, as our websites are mostly static and It allows me to use the same old HTML format. Non-developers sometimes need to read my code, so ejs retains the old HTML syntax.

Whereas pug is more cleaner and easier to read, but that would require me to rewrite the code, which wonā€™t work for me at work as we quite often use premade templates. (aka HTML code written by others).

I will use ejs for work /working with non-developers, and use pug while working alone.

They all work in a similar way, but the handlebars style syntax: {{ title }} is becoming the standard. As well as handlebars, it is also used for interpolation by Angular and Vue.js. Itā€™s easier to read (and type) than EJS, I think.

1 Like

For me, Razor is more concise and syntactically close to native HTML and JS.

// Pug example:

unless user.isAnonymous
  p You're logged in as #{user.name}

ul
  each val in numbers
    li= val

vs

// EJS example:

<% if (!user.isAnonymous) { %>
  <p>You're logged in as <%= user.name %></p>
<% } %>

<ul>
  <% numbers.forEach(function(val){ %>
    <li><%= val %></li>
  <% }); %>
</ul>

vs

// Razor example:

@if (!user.isAnonymous) { 
  <p>You're logged in as @user.name</p>
}

<ul>
@for(var i = 0; i < numbers.length; i++){
    <li>@numbers[i]</li>
}
</ul>

How about Nunjucks by Mozila?

The syntax looks similar to EJS.

Coming from HTML and learning templates I would say EJS is easier to grasp, itā€™s very close to plain HTML and uses same elements.
After working a lot with ASP.NET and Razor I had an easier time with EJS.

Classic ASP syntax was pretty similar to EJS:

<ul>
<%for i = 0 to 10%>
<li><%=i%></li>
<%next%>
</ul>

Then they developed Razor, the purpose of that was to simplify and improve the syntax. I couldnā€™t agree that the example above is easier to read and write than the same written in Razor syntax - for me, itā€™s not faster, not shorter, not clearer to write <%...%> characters at the beginning and end of each code line or expression. But as itā€™s known ā€œbeauty is in the eye of the beholderā€.

Depends upon what client-side MVC framework you want use, Angular or Backbone or Ember and also are you a HTML lover. In my opinion, the best view engines are the ones that help developers avoid security flaws, like cross-site scripting (XSS).

.ejs is the best template engine after i read those comments on my way.

Prefer Handlebars myself.

http://handlebarsjs.com/ā€™ looks like react component

Yeah, looks similar in some ways.

I would like to further expand your endeavor by showing you all the available template engines, here is a blog post that can give you a brief on each one: https://shieldfy.io/blog/template-engines-nodejs-developers/ . For any further inquiries ask here or on the blog post, and I am glad to help.

I think Edge would be the best option.

I love ejs itā€™s better and you can write also plain html

I remember myself using Razor templates in .NET. Is there a possible way of using Razor templates outside of .NET project, like in normal HTML file? I tried searching for possible answer but couldnā€™t get any.