Display the data
Nelisa wants a comprehensive weekly online sales report.
Publish the sales report online using GitHub Pages. Use your Nelisa repository. The URL will be something like http://username.github.io/repository.
Handlebars templates and layouts can be combined with data to produce HTML files (and other things).
Create:
- HTML reports using Handlebars templates;
- HTML files from the strings created by Handlebars by using Node JS’s
fsmodule to create files on disk; - a
.htmlfile for each week’s statistics; - a homepage called
index.htmlthat links to each week’s file.
Separate template files
Inline Handlebars templates become cumbersome quickly. A way around that is to store them in separate files and use the fs module to read the templates from disk.
More with Mocha
Mocha has several ways to display the data: reporters. To see which reporters are available, run mocha --reporters. To use the dot reporter, for example, run mocha --reporter dot or mocha -R dot. Try a few out and see which one(s) you like.
Now let’s save a copy of the tests using the markdown reporter. Run a command something like this:
mocha -R markdown > YYYYMMDD-results.md
This puts the result of mocha -R markdown into a file called YYYYMMDD-results.md.
Learning areas
- Templating using Handlebars with NodeJS.
- Creating files with the
fsmodule. - Storing and using Handlebars templates in separate files using the
fsmodule.