Templating helps in converting the content of the static html page to dynamic. By using templating engines we can replace the values in html document with the actual data values. For example, if we want to show the employees and their details then we can render the html page with this data using the templating in Express Js.
There are various templating engines available in Express Js like ejs, pug, etc. All the templating engines have their own syntax. In this article we will discuss about ejs.
Templating in Express Js using EJS
EJS stands for Embedded Javasript Templating. EJS is used to produce the final HTML document after adding the dynamic content from database or after some calculations. We can also write javascript inside HTML pages using react. We can use almost all the necessary things like conditional statements, loops, etc.
Setting up the EJS and using it in the Express Js project
First we have to install it in our project, using the command :
npm i –save ejs
For using EJS inside our HTML pages, we have to save the HTML files using the .ejs extension.