Day 13: Models, Routes and Custom Modules

Reminders for Tony

  1. Put on mic
  2. Open Zoom chat
  3. Record! Anyone else?

Topics Covered

  1. EJS quickie
  2. Model fixtures withrequire() and module.exports
  3. Dynamic endpoint handlers with request.params

Goal for the day

We’ll start the day with a long list of animal endpoint handlers. By the end of the day, we should have all animal pages served with one endpoint (GET /:id).

Topic 1: EJS quickie

We will discuss the EJS alternative to Pug. While Pug has some great features, it can be difficult to create page partials, so we will quickly walk through the example from yesterday using EJS.

Activity objectives

  1. Choose an engine: Pug/EJS
  2. Convert your Assignment 2 html files to view files.

By the end of this activity, you should have no static html files in your public directory. They should be moved to your views directory.

Mid-day Huddle

  • who needs help?
  • any pivots?
  • any show-and-tell?

[lunch]

Topic 2: Model fixtures with require() and module.exports

We will discuss the model in deeper detail.

Activity objectives

Assignment 1 and 2 linked your Destinations to random websites. Try creating a destinations.js module that you can use to import your destinations model into your app.

Topic 3: Dynamic endpoint handlers with request.params

See:

Activity objectives

  1. Using today’s finished code, refactor the GET /:id endpoint so that it uses the animal title instead.

Summary

  • any trophies?
  • prep for tomorrow?
  • applause

Categories:

Updated: