Mike Valstar
See Coding with Node.js: Part 1; Getting started with Express. for the beginning of this tutorial series. With the admin login page completed we now need a list of blog entries and a way to create and edit them. So to start lets give ourselves an admin interface for blog posts that we can later integrate into the main website.
For the blog posts i'm going with the below structure for the posts to fit my blog. One key column I'm adding in is the external link, this will be very useful for determining posts that are not full articles like this one but comments on something else that I would like to link to. So lets first add the structure to the database
Now that we have our database structure setup we'll need to setup a page to display all of the current posts and provide a link to create a new one.
The first step we need to add is creating the post. Because we want to keep an id for our posts that is short and numeric we're using the sid column to link to posts; and we need to find the maximum for the column before we start a page as seen below. Also we need to check for when a user posts back the data in the form and apply that to the database.
Also note above that we set the post id to 1 when no maximum post id can be found.
With the ability to add/edit blog posts we can now start translating all the posts into the database and be ready to switch over to a db driven blog listing.
All code created for this website is available on the github page and this tutorial specifically is available here: https://github.com/mikevalstar/mikevalstar_com/tree/Node_Tutorial_pt4
In the next part of this series we can show these blog posts on the front page. And later an RSS feed.