February 21, 2020
Express Handlebars
What the heck is this?
This is tricky to answer as there is "express", there is "handlebars",
and there is "express-handlebars".
As near as I can tell, they are all different (albeit related) node.js
packages.
To add to the confusion, there is also "hbs" and "express-hbs" where
"hbs" is some abbreviation for "handlebars", but is also an
entirely different package.
To add even more confusion, handlebars at least can be used either
client side or server side.
Sorting out the relationship (or lack thereof) between all of these is
somewhat of a pain in the ass.
There is a bunch of history going on.
Many documents assume (as so much crummy documentation always seems to) that you are not
starting from scratch, but have used and are familiar with every package that came before
in the history of the software. This also means that tutorials for some now deprecated
package can actually be useful.
Express
There is a node package called "express".
Express is the low level "backend" of a node.js server.
It can be installed using npm, or on my Fedora system
via "dnf install nodejs-express".
Handlebars
This is another node package.
Handlebars is a "templating engine" for node.js
It too can be installed via npm, or on my Fedora system
via "dnf install nodejs-handlebars"
(I am not using this, but am using the next package).
Express-handlebars
The only resource I found that gave a sensible starting point was the Github page.
It turns out you have to install both the regular "express" package along with
the "express-handlebars" package. This is only obvious from the two require
statements in their example. The simple example requires a definite directory
structure and files with certain names. For a directory structure you need
both "views" and "views/layouts", with files in each.
Here is the whole thing in a tar file. Once you have both express and express-handlebars
installed, you should just be able to untar this into a directory and type
node app.js
And it will run a web server on port 3000.
Where do we go next
The Fish farm tutorial indicates a lot of the syntax and markup of handlebars,
but not the file layout.
The Intro to handlebars article is actually pretty good, but is clearly just a part of some bigger
thing that I don't know how to get started with.
Adventures in Computing / tom@mmto.org