PUG vs HTML, which one is better to render data to the view page in Node.JS (express)
Asked Answered
S

3

6

I am new in Node.JS stack. I saw a big number of developers are using pug template engine (Express JS) instead of regular HTML. If anyone of you have used pug can you please tell me the major benefits of using pug over HTML view technology?

Stronski answered 18/9, 2019 at 12:17 Comment(0)
C
6

First, let's discuss the Pug framework. Pug framework is a highly flexible framework which supports the generation of HTML content dynamically for almost any sort of data. You can write the Pug template to create -

User Profiles, List of store items, Templated HTML documents, Conditional blocks in the web pages

We can render and create the conditional blocks and iterative structures to produce the dynamic HTML web content instead of hardcoding everything.

Node.js runtime supports Pug templates by default ㅡ the template engine is Jade by default, however, Jade has been renamed to Pug. You can continue using Jade engine, but it is recommended to use Pug templates. Pug templated files are written as below.

 doctype html  
html  
    head  
        title My Page  
    body  
        h1 Heading  
        p My paragraph here.  

This will get translated to the following HTML content on demand.

<html>  
   <head>  
      <title>My Page</title>  
   </head>  
   <body>  
      <h1>Heading</h1>  
      <p>My paragraph here.</p>  
   </body>  
</html>  
Cavort answered 18/9, 2019 at 12:24 Comment(0)
C
1

Fast answer: HTML.

Why? Because it is processed only by the browser, so you are removing one layer of your stack (compiling PUG). It will make your application somewhat lighter.

But PUG is an awesome tool. It offers nice maintainability for your code and a strict code style. It is useful when working with more people and it feels great.

Also, PUG increases my code efficiency by 20% in SublimeText.

Clare answered 18/9, 2019 at 12:22 Comment(0)
S
0

It is not accurate to say that one language is "better" than the other in general. Both PUG and HTML can be used to render data to the view page in a Node.JS (Express) application, and the choice of which one to use will depend on your specific needs and preferences.

PUG is a template engine that is designed to be easy to read and write, with a focus on simplicity and expressiveness, while HTML is the standard markup language for creating web pages. Both languages have their own unique features and syntax, and either one can be a good choice depending on the requirements of your project.

For full article refer to https://www.ubercompute.com/blog/benefits-of-using-pug-template-over-traditional-html/

Saad answered 20/12, 2022 at 13:12 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.