DEV Community

Kim John
Kim John

Posted on

Pug vs EJS?

I have to decide whether to go with PUG or EJS for a node web app.

I highly appreciate if you can suggest one over another explaining why you think so.

Appreciate all help!

Top comments (18)

Collapse
 
nepeckman profile image
nepeckman

The two are roughly equivalent in terms of functionality, so it comes down to what syntax you prefer. I have very strong feelings about this: I despise ejs syntax. All the special characters add noise to the code and increase your surface area for mistakes. Its takes longer to read, it takes longer to write, and it takes longer to find bugs. However, ejs syntax is an expansion of HTML where pug syntax is completely different, so I can see why some might prefer ejs. I would spend a little time writing in each, then decide which one works best for you.

Collapse
 
jkimquickdev profile image
Kim John

That is a neat reply. I agree with you. I'm personally comfortable with EJS since I know HTML very well. But you know lately, I started digesting PUG script, where I don't see any tag, it's clean code. So, I think I will go with PUG, it's a little weird in the beginning but better in the later part. Anyway, thanks for the recommendation.

Collapse
 
ben profile image
Ben Halpern

I'm personally comfortable with EJS since I know HTML very well

From my experience, this is important. Even though EJS is kind of ugly, IMO it's much easier to pass around between different people without confusion. With PUG, you're really buying into a wholly different universe, that's probably cleaner and easier to use in and of itself, but different in ways that can matter.

IMO EJS is the more practical solution, even if it isn't "better".

Thread Thread
 
jkimquickdev profile image
Kim John

Thank you Ben, I share your view too. I had that experience today itself only when one of my colleagues saw my PUG script and freaked out. I thought I better go with EJS since everybody knows HTML. Anyway, Thanks for your input on this.

Thread Thread
 
ben profile image
Ben Halpern

I think it’s great to go through the process of asking this question. There’s no right answer but at least it’s not all in your head anymore.

Thread Thread
 
jkimquickdev profile image
Kim John

Agree 100%. :)

Collapse
 
matthewbdaly profile image
Matthew Daly • Edited

I'm not fond of either. I haven't used Pug since it was Jade so my experience of it may not be up date date, but I always found it too terse for my liking and too different to HTML. I haven't used EJS at all, but it looks a lot like Underscore templating which I always found cumbersome.

I agree with Meghan that Handlebars is also worth a look. I've used Handlebars a lot (my site is built with a static site generator I wrote that uses Handlebars), and it has a very shallow learning curve.

Alternatively, have you looked at React.js? It's my usual go-to for JS templating these days and can be used to render the same template on client and server side. It's more complex than the others as it also includes things like event handling, so it might be overkill for you, but for some use cases it can be a boon.

Collapse
 
jkimquickdev profile image
Kim John

Thanks for the comment, Mark. I find react is a little bit overkill for the kind of project I'm doing. In other words, I need something really simple. Given the site is static, my goal to reuse the pieces of HTML code, that's it.

Collapse
 
matthewbdaly profile image
Matthew Daly

In that case, Handlebars should be a good fit. It supports partials, and you can create your own helpers. The syntax is IMHO simpler than EJS or Pug too.

Collapse
 
joehobot profile image
Joe Hobot

Why not Beagle? Sniffs bugs better than Pug

/s

Wish I could give you better suggestion but at the end of the day it is more of a personal preference. Longer time ago I was between Java or Python? I liked Python more because at that time I was very confused how much stuff I need to write in Java vs Python. So I picked something that was easier for me to understand and then I went upwards from it.

Collapse
 
jkimquickdev profile image
Kim John

Thanks Joe for the comment!

Is Sniffs bugs node package, I couldn't find it.

I found BeagleJS but it's a web scraper.

Collapse
 
nektro profile image
Meghan (she/her)

I had things I didn't like about either, so I made my own haha. But out of those two, definitely Pug.

Collapse
 
nektro profile image
Meghan (she/her)

I'd even recommend Handlebars over both of those.

Collapse
 
jkimquickdev profile image
Kim John

Handlebars seem interesting!! Thank you for your suggestion! I will give it a shot too.

Collapse
 
andrewbaisden profile image
Andrew Baisden

Late answer but EJS gets my vote. What type of App did you create did you use EJS?

Collapse
 
jkimquickdev profile image
Kim John

nunjucks is really interesting, thanks for the suggestion. I'll look for into it.

Collapse
 
mohamed_gt57 profile image
Mohamed Atef

Could I write pug.js inside an ejs file? So, If I have a file with ejs extension could I write pug.js code in it?