There are three parts to a site—or at least, to the sort of site we’ll be building: the client, the server, and the database. I’ll go over each of those sections and talk about the libraries and frameworks we use in them, and what they do.
Might as well begin at the beginning! The server is the most basic part of the site; without client-side scripting or a database, you can still have a webpage that has information on it and does stuff, but without a server, you’ve got nothing but a browser, and maybe a 404 error. The server is the software that responds to requests from the outside world. When you build a server, you define things like what port the server is listening for signals on, what information is sent out when someone makes a GET request at a particular path with a particular query, where information goes when a user wants to PUT it somewhere, and all that good kind of stuff.
One of the main node modules that we use is Express. Express basically takes what you can do with node and cleans it up, tightens up some syntax, predefines some stuff, and generally makes things quicker and easier to work with—assuming you know how to use it, ’cause the documentation for Express is terribad.
The next important chunks of code that we use on the server are Consolidate and Handlebars. These two are very closely related. Consolidate is basically an interface layer for templating modules—that is, it’s a translator that lets a bunch of different template engines talk to Express in a way that Express understands. So what are templating engines? They let you generate html quickly and easily on the fly, basically. Your pages start to look like this example from the Handlebars page:
The title and body would then get filled in automatically by whatever the server generates in response to the client’s request. The name Handlebars comes from the way the curly braces look like little moustaches on their sides, apparently. Being in Portland, hipster capital of the universe, this doesn’t really surprise me, but it does make me shake my head and sigh.
- fs: This lets us work with the file system. It’s how we can do things like traverse directories and read files. Important, for sure, and a baked-in part of node.js.
- path: kinda similar to fs, this lets us work with file paths. Like fs, it’s part of node.
- body-parser: We use this for parsing JSON, which is a pretty popular data storage format
- morgan: This is an error logger. Useful to have around, especially for development!
The next module we’ll talk about is called Orchestrate. It’s technicaly on the server, but everything it does it on the databse—itbasically the interface between server and database. Different databases use different modules, of course—we’re using Orchestrate, which is a pretty neat little database as a service outfit here in Portland. They offer a certain number of queries per month for free, and after that you have to start paying. Anyway, their Orchestrate module is the link between the server and the database.
This has gotten longer than I thought it would, though, so I think we’ll wrap up here for now, and save the discussion of client-side stuff for another day.