WDX-180
Web Development X
Week 35 | Advanced JavaScript
Week 35 - Day 1 | Mini CMS Project
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: Decompose our main app into a web server and a database file. Talk about asynchronous code.
- Part 2: Continue our talk on asynchronous code and async/await. Database PRIMARY and FOREIGN keys.
You can find the lecture code here
Exercises
- Study: how import (ESM) vs require (CommonJS) behave in Node (20+)
- Nodejs Docs
await
is ONLY awaiting for Promises:await setTimeout()
❌
- Convert the async function into a Promise using the
new Promise()
and then await: await promisifiedSetTimeout()
- Make HTTP requests from the CLI:
cURL
andwget
- cURL: curl http://oxylabs.io
- https://nodejs.org/en/learn/modules/anatomy-of-an-http-transaction
- Tasks/Challenges:
- Find out a better way to create and format the output HTML. For example, create a template function:
show_template(page_type,vars)
- Create and return a Login page
- Make sure to handle the
req.url
splitting appropriately. Now, if there is no?user_id=100
, the code breaks - Make sure that if the user is not found in the DB, you get some response
- See if you can serve a favicon and some CSS along with the pages
- Create a 404 page
- Find out a better way to create and format the output HTML. For example, create a template function:
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/week35/progress/progress.draft.w35.d01.csv
You should NEVER update the draft
sheets directly, but rather work on a copy of them according to the instructions found here.
Week 35 - Day 2 | Mini CMS Project
Schedule
- Practice on the topics and share your questions
Exercises
Yesterday, we returned some HTML from the web server (web.ts). This was just a simple template String literal. We can abstract this in a function for better re-usability.
The web server checks the pathname using a basic if conditional and returns a custom HTML. By adding more paths, this code will become complicated and bloated. Maybe you can think of an abstraction so that the request pathname => appropriate HTML works better than the current implementation.
Starting from this code on the CMS repository, (1) create a function that returns the HTML content based on the pathname and some dynamic values. (2) Create an abstraction over the server router: pathname => load data => render HTML
Important: The code link above, points to a particular commit in the repository. Click the Code
=> Download Zip
button on GitHub, to download the code as it was in that exact commit.
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/week35/progress/progress.draft.w35.d02.csv
You should NEVER update the draft
sheets directly, but rather work on a copy of them according to the instructions found here.
Week 35 - Day 3 | Promises
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: More about Promises & the Promise Constructor
- Part 2: Chaining Promises
You can find the lecture code here and here
Exercises
- Study: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Promise
- It’s important that you go through the whole document and probably more than once to fully understand the Promise concept.
- Equally important to run all the examples mentioned there and tweak them to experiment with variations to get an even better and deeper understanding.
- Explore number
#11
from the promises.js reference
- It’s important that you go through the whole document and probably more than once to fully understand the Promise concept.
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/week35/progress/progress.draft.w35.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 35 - Day 4 | Practice Day
Schedule
- Practice on the topics and share your questions
Study Plan
Today is practice day. Practice on the topics covered so far and share your thoughts, questions and insights.
Happy hacking!
Week 35 - Day 5 | Q&A and Mini CMS Project
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: Logical AND and OR operators. How do we connect a domain to our hosted app? Website analytics.
- Part 2: SQL Injection. Mini CMS project: Creating a form for creating content.
You can find the lecture code here and the logical operator code here.
Important: The code link above, points to a particular commit in the repository. Click the Code
=> Download Zip
button on GitHub, to download the code as it was in that exact commit.
References & Resources:
- SQLite Injection Attacks
- process.cwd(), __dirname, __filename
- https://stackoverflow.com/a/9874415/4861760
process.cwd()
vs__dirname
- https://nodejs.org/api/path.html#pathsep
- https://nodejs.org/api/path.html#pathnormalizepath
- https://nodejs.org/api/path.html#pathbasenamepath-suffix
Exercises
- Highly recommended challenges:
- Turn callback-based async functions into Promise-based functions
- Work with both .then().catch().finally() and async/await/try/catch/finally syntax
- Try to promisify:
- Node.js fs methods, e.g. turn these
fs.writeFile(cb)
,fs.readFile(cb)
into something like awaitwriteFileP()
,await readFileP(filename)
- The navigator.geolocation methods: getCurrentPosition
- The
new Image()
load/error callbacks - The XMLHttpRequest object
- Node.js fs methods, e.g. turn these
- Try to promisify:
- Work with both .then().catch().finally() and async/await/try/catch/finally syntax
- Turn callback-based async functions into Promise-based functions
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/week35/progress/progress.draft.w35.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!