Back to overview

Let's Play with Template Engines for NodeJS

June 08, 2020

Working with template engines will allow you to dynamically generate HTML markup with JavaScript for your different page in a Node app which does not make use of any frontend library or framework like React or Angular.

There are many options out there for quick templating. Pug and EJS seem to be the most used. So, let’s test them and if they’re worth using.

Template Engines in a Nutshell

In a nutshell templates let us separate the HTML structure from the content contained within. They generally come with new syntax but are not at all difficult to work with. A little brush up in the docs will let you go.

You have templating systems in most other languages too. To name one, Twig is used in PHP world.

What we’ll Build

For the purpose of this tutorial, I want you build a simple app with 2 pages. The first page displays a list of quotes and the second one a list of authors.

You can find the demo here and the final code on Github.

To start out, go and clone the starter code here.

Pug - the Big Picture

A Quick Introduction to EJS