Using a template package
The examples so far in this chapter have demonstrated how templates can be used to render content and show how some basic features can be easily created. For real projects, it makes more sense to adopt one of the excellent template packages available for JavaScript. Run the commands shown in Listing 10.21 in the part2app
folder to install one of the most widely used template packages, which is named Handlebars, and a package that integrates it into Express.
Listing 10.21: Installing a template package
npm install [email protected]
npm install [email protected]
There are many template packages available, and they all offer similar features. The main difference between packages is the way that templates are written and how expressions are denoted. The {{
and }}
characters are a common way to denote expressions, and they are known as mustache templates because the curly braces are reminiscent of a mustache. The Handlebars
package (https:/...