Trusted answers to developer questions
Trusted Answers to Developer Questions

Related Tags

javascript
expressjs
nodejs

What is a view engine in Express.js?

Rumaisa Habib

Overview

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).

Example

<!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>

Explanation

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.

The rendering process for the web app

RELATED TAGS

javascript
expressjs
nodejs

CONTRIBUTOR

Rumaisa Habib
Copyright ©2022 Educative, Inc. All rights reserved
RELATED COURSES

View all Courses

Keep Exploring