WDX-180
Web Development X
Week 34 | Mini CMS Project
Week 34 - Day 1 | Building a Mini CMS - Part 1
Schedule
- Watch the lectures
- Study the suggested material
- Practice on the topics and share your questions
Study Plan
Your instructor will share the video lectures with you. Here are the topics covered:
- Part 1: What is a Content Management System (CMS)?
- Part 2: Setting up our Node.js project
You can find the lecture code here
References & Resources:
- How to set up a Node server with TypeScript in 2024
- Learn with Jason
- VSCode Excalidraw Extension
- TypeScript definitions for node http (@types/node)
- How to use TypeScript in Node.js
- Some more Node/TypeScript boilerplates and guides
- Try WordPress Playground
Week 34 - Day 2 | System Design
Schedule
- Study the suggested material
- Practice on the topics and share your questions
Study Plan
Since we are going to be designing our Database soon, here are two really interesting videos that will walk you through designing a system (an Instagram-like app in one case, a calendar app in the other).
You can learn a lot from this process, such as thinking about the system from a high level and breaking it up in different modules and deciding on the Database entities (tables) and Schema (columns and types).
Enjoy and gain some insights!
Week 34 - Day 3 | Object Relational Mapping
Schedule
- Watch the lectures
- Study the suggested material
- Practice on the topics and share your questions
Study Plan
Your instructor will share the video lectures with you. Here are the topics covered:
- Part 1: Databases & ORMs (Object Relational Mapping)
- Part 2: Modular architecture and creating and populating Database tables with data
You can find the lecture code here
References & Resources:
- Dark Reader Chrome and Firefox extension
- GitHub
- ORM: Object–relational mapping
- Modular Architecture
- Think simple
- Google for “modular architecture”
Exercises
- Search for patterns to connect the web server module and the database module
- Study the
sqlite3
API documentation
IMPORTANT: Make sure to complete all the tasks found in the daily Progress Sheet and update the sheet accordingly. Once you’ve updated the sheet, don’t forget to commit
and push
. The progress draft sheet for this day is: /user/week34/progress/progress.draft.w34.d03.csv
You should NEVER update the draft
sheets directly, but rather work on a copy of them according to the instructions found here.
Week 34 - Day 4 | Practice Day
Schedule
- Study the suggested material
- Practice on the topics and share your questions
Study Plan
Today is practice day. Practice on the topics and coding challenges for the Mini CMS project we are working on and spend some time on MDN and other Internet resources to read more about the technologies involved.
Week 34 - Day 5 | Mini CMS: Database Connection
Schedule
- Practice on the topics and share your questions
Study Plan
Let’s practice! Skip to the Exercises
section below for
a guide on what to code today.
Exercises
Take this opportunity and try to work on the CMS project (you can find the code to start from here) to accomplish the following tasks:
-
Create a new
src/db/basic.ts
file and paste the officialsqlite3
example found here: https://github.com/TryGhost/node-sqlite3?tab=readme-ov-file#usage. We’ll just keep the other database-related files aside for now. -
Instead of creating a sample
lorem
table, like the example, update the code and create 2 tables that will hold our CMSUsers
and their BlogPosts
. Make sure that these two tables have a one-to-many relation, where oneUser
can create manyPosts
. Make use of thePrimary/Foreign Keys
to connect the two tables and populate then with a few sample users and posts. ChatGPT can help you come up with some sample user names, blog post titles and sample content. -
Think carefully about the Schema of these two tables (column names and value types).
-
Rename
src/index.ts
tosrc/web.ts
and create a new file namedsrc/index.ts
. Find a way to import both thesrc/db/basic.ts
andsrc/web.ts
intosrc/index.ts
and “wire” them up correctly so that the web server starts listening when the database has been initialized and the table creation (CREATE TABLE) and population (INSERT INTO) have completed. You will have to create some functions and of course make use of some callbacks in order to achieve that. -
Create another route named
/blog
that will read the contents of thePosts
table and send the contents back to the user in the form of an HTML page.
Here is some code to get you started:
index.mjs:
import webInit from "./web.mjs";
import dbInit from "./db.mjs";
dbInit( webInit );
web.mjs:
export default function webInit(db){
console.log("Web server initialized!");
function listen(){
console.log("Table:", db);
}
listen();
}
db.mjs
export default function dbInit(cb){
console.log("Database server initialized!");
setTimeout(()=>{
console.log("Table ready!");
cb({ table: "Users" });
},500);
}
Run: node index.mjs
Output:
Database server initialized!
Table ready!
Web server initialized!
Table: { table: 'Users' }
That’s it!
IMPORTANT: Make sure to complete all the tasks found in the daily Progress Sheet and update the sheet accordingly. Once you’ve updated the sheet, don’t forget to commit
and push
. The progress draft sheet for this day is: /user/week34/progress/progress.draft.w34.d05.csv
You should NEVER update the draft
sheets directly, but rather work on a copy of them according to the instructions found here.
Weekly feedback: Hey, it’s really important for us to know how your experience with the course has been so far, so don’t forget to fill in and submit your mandatory feedback form before the day ends. Thanks you!