Adding a view layer
At a basic level, web frameworks are responsible for delivering dynamically generated HTML to a web browser.
We tend to use a view layer of some kind, generally in the form of a template language, as a declarative way to integrate data with HTML to produce the desired combined output.
In this recipe, we'll learn how to use views with Express, and in the There's more... section we'll explore the same with Hapi and Koa.
Getting ready
For this recipe, we're going to copy the Express application from our Creating an Express web app recipe (we'll cover view layers for Hapi and Koa in the There's more... section).
Let's copy the folder called express-views
and add the ejs
module:
$ cp -fr creating-an-express-web-app/app express-views$ cd express-views$ npm install --save ejs
How to do it...
Let's start by creating a views
folder and placing a view file in there, which we'll call index.ejs
:
$ mkdir views$ touch views/index.ejs
Next we'll configure Express using app.set
to configure the...