Book Image

Mastering Web Application Development with Express

By : Alexandru Vladutu
Book Image

Mastering Web Application Development with Express

By: Alexandru Vladutu

Overview of this book

Table of Contents (18 chapters)
Mastering Web Application Development with Express
Credits
About the Author
About the Reviewers
www.PacktPub.com
Preface
Index

Integrating a template engine with Express


In the remaining part of the chapter, we are going to integrate a template engine with Express, specifically the template function from the lodash module (this can be applied for other template engines too).

But what do we have to do exactly? We are going to tackle the following issues:

  • How the template engine's rendering function gets called (what arguments are called)

  • What the function should return

  • Caching and cache invalidation

  • Partials and layouts

The rendering function from Express calls the template engine function with the following arguments:

  • The path of the template file

  • The locals passed to the response.render function when called (as the second argument)

  • A callback function that should be called with the (error and content) arguments

Let's make a small sample application and an empty view file and see exactly what gets logged to the console:

app.set('views', __dirname + '/views');
app.engine('html', function() {
  console.log(arguments);
});

app...