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

Template engine consolidation with consolidate.js


Not all template engines have out-of-the-box support for Express, nor do they have the same API.

Consolidate.js (https://github.com/visionmedia/consolidate.js) is meant to help with that and provides the same function signature for the various template engines it supports. Another benefit of this module is that it makes it easy to switch from one engine to another with minimal effort. The signature it supports is the same as the one used in Express: (path[, locals], callback).

To use a certain template engine, we still have to install it with NPM, but the rest is just a few lines of code in our server setup:

var cons = require('consolidate');
app.engine(jade', cons.jade);

From this point on, we can just use response.render() as we have done before.