

To run this page, add the following route to your app −Īpp.get('/first_template', function(req, res) syntax.

Inside that create a file called first_view.pug, and enter the following data in it. Add the following code to your index.js file. Now that Pug is installed, set it as the templating engine for your app. To use Pug with Express, we need to install it, There is a lot of ground to cover on this. Pug is a very powerful templating engine which has a variety of features including filters, includes, inheritance, interpolation, etc. Templating engines are used to remove the cluttering of our server code with HTML, concatenating strings wildly to existing HTML templates. Let's start by creating an h1 that says 'Hello, Pug'.Pug is a templating engine for Express. Part of this is due to the fact that you don't have to worry about closing tags, which can help lead to much cleaner files. There are some other items that make it a little different when writing it, but the elements, attributes, and structure are all the same as standard HTML.Ĭreating markup for a webpage in Pug may feel a bit strange at first, but after a bit will start to feel pretty intuitive. The key to writing Pug is indentation because when Pug is compiled into HTML, the indentation is how it determines how to nest the elements. It has become a widely used templating engine for many websites, and for good reason: If you know how to write HTML, this will feel like a shorthand version of it. Pug, formerly known as Jade, released it's 1.0.0 version on Decemafter being in development for a few years. Today I will be talking about one of the most popular templating languages for Node.js applications, Pug. These languages allow you to write HTML like structures while retaining the ability to insert variables and use logic within the structure. The engines used in the aforementioned tools are Twig, Blade, and Edge, respectively.

A templating engine is a tool that a framework can use to assist in scaffolding a front-end for a website or webapp. If you've ever used something like Drupal, Laravel, or Adonis, you've likely encountered a template engine.
