Using template engines
Template engines allow you to generate HTML code in a more convenient way. Templates or views can be written in any format, interpreted by a template engine that will replace variables with other values, and finally transform to HTML.
A big list of template engines that work out of the box with ExpressJS, is available in the official website at https://github.com/expressjs/express/wiki#template-engines.
Getting ready
In this recipe, you will build your own template engine. To develop and use your own template engine, you will first need to register it, then define the path where the views are located, and finally tell ExpressJS which template engine to use.
app.engine('...', (path, options, callback) => { ... }); app.set('views', './'); app.set('view engine', '...');
Before you start, create a new package.json
file with the following content:
{ "dependencies": { "express": "4.16.3" } }
Then, install...