Server-side templating
Up until now our Express server has only served JSON; let's install a couple of modules that will assist us in serving HTML.
consolidate.js
is a template engine consolidation library that was created to map all of Node's popular templating engines to the Express convention for templating, allowing them to work within Express:
npm install consolidate --save
handlebars.js
is an extension to the mustache templating language. Handlebars is a logic-less templating language that keeps view and code separated:
npm install handlebars --save
In order to be able to serve our handlebar templates, we will have to make some changes to our Express server. Let's change the default template engine to handlebars by setting the app.engine
:
app.engine('html', cons.handlebars);
Now register html
as our view file extension. If we did not set this, we would need to name our view index.hbs
instead of index.html
, with .hbs
being the extension for handlebars templates.
app.set('view engine'...