View engines allow us to render web pages using template files. These templates are filled with actual data and served to the client.
There are multiple view engines, the most popular of which is Embedded Javascript (EJS).
<!DOCTYPE html> <html> <head> <title>My first view engine!</title> </head> <body> <h1> <%= heading %> </h1> <h4> <%= text %> </h4> <h5> The time is: <%= time %> </h5> </body> </html>
Line 11: A response is rendered when a request is sent to the homepage. It selects an EJS file (in our case, myEJS.ejs
) as a template to which arguments are passed from the Javascript file. This lets us create multiple HTML pages using the same base template. They may, however, have different values to be passed to them.
Free Resources