Stack
Node.js
MongoDB
Pug
Passport
Express
TailwindCSS
Project Goals
The main goal of this project was to have two different front ends, one for public users and one for admins. Guests can view all admin posts, and authorized admins can access forms to create posts, as well as edit and delete content. I chose to make my website a book blog, where posts are either book reviews or monthly reading wrap ups.
Development Stack
I created the webserver using Node.js, along with Express to handle routing. I used two different databases for my website, Firebase for storing photos as well as MongoDB's Mongoose library for storing data and user information. User passwords are encrypted with Bcrypt. Passport, through local strategy, handles user authentication as well as session persistence. The front end for this project is built with Pug and TailwindCSS. I decided to use a CSS framework for this project because I've found naming classes can lead to disorganized code and slower development.
Development Process
I went through a few database structures for this project. I knew I wanted to have different types of posts that displayed as a feed on the homepage. Instead of having one post schema, that had many different optional keys depending on the post, I decided to write separate schemas. This allowed for a more strict schema, which leads to fewer issues in the data later on, and takes advantage of the benefits to Mongoose's schemas. Since the database has different collections of posts, I spent more development time writing queries, and needed to use MongoDB's aggregation pipeline to sort every type of post together.
Lessons Learned
I practiced writing queries and using aggregation pipelines for this project. I learned how to access document virtuals from aggregate results using hydrate from Mongoose's API. I implemented infinite scrolling, limiting the time it takes to load and display large datasets by only returning sections at a time.