At the beginning of the chapter, we adopted the mechanism of templates called EJS, which is very easy to understand. Besides, EJS gives us the template logic functionality within its syntax and can be easily embedded within HTML files. Its use is very similar to that of Handlebars, another excellent JavaScript library to use templates; for example:
<h1><%= title %></h1> <ul> <% for( var i = 0; i < bands.length; i++ ) { %> <li> <%= bands[i] %> </li> <% } %> </ul>
It is very similar to other programming languages such as PHP and RoR.
However, you can use the template that suits you; Node.js has a great list of template engines for all tastes.
Tip
Another good option for a template engine is Swig, which can be installed through the npm
command:
npm install swig
Let's create the following files' templates in the
views
folder:login.ejs
profile.ejs
signup.ejs
Also, we will create a...