Learning about the world of JavaScript can be incredibly daunting.
Learning Node is even worse.
Carrying on to the third iteration of the node-only-server! I improved the front end by incorporating an HTML templating module. I looked into both handlebars and pug, and ultimately decided on pug.
Data model is still crap, as I'm just using file I/O rather than a database.
Fortunately I was already familiar with HTML templating from a blog I wrote using Jekyll and Liquid. In this case, the challenge came from sorting through all the available templating engines for JavaScript and picking my favorite.
I implemented my index view with both handlebars and pug. At the outset they seemed nearly equivalent, the primary difference coming from the fact that pug doesn't use tags and relies on indentation. But as soon as I began using template partials and inheritance to modularize the HTML, it was clear that handlebars was severely lagging behind.
So I ultimately chose pug, which as a bonus is the default view engine for Express.
Now that my HTML generation is super slick, I really need to improve my archaic data model by incorporating a database into the project!
This simple web application tracks weight measurements. It implements the following HTTP methods:
It also offers one page, the index, which shows the current weight entries.
First, clone down the repository. Next, run the following command from inside the directory:
npm start or node server
In order to access the index page, navigate to localhost:3000 in your browser.
Use your favorite REST client, mine is Postman, to send requests to the server.
GET /api/weight
POST /api/weight
Parameters: { "date": "2017-05-17", "weight": 180 }
PATCH /api/weight/:date
Parameters: { "weight": 180 }
DELETE /api/weight/:date