What is a view engine in Express.js?

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>
The basic syntax for view engines

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

Free Resources

Copyright ©2025 Educative, Inc. All rights reserved