what kind of train does node take on its commute
express— @netlify
HTTP cat by @girlie_mac.
Before you start you'll probably want to read a bit about express, routing, and templating. We'll cover this in the lecture but make sure you fully understand these concept, the resources below can help.
🎦 Watch a video about routing and express.
🎦 Watch a video about request and response.
You can do these exercises before you start working on the assignments to get comfortable with the topics covered in class. The below are interactive self guided lesson modules from freeCodeCamp. If you feel a bit more adventurous you can try the NodeSchool workshoppers.
In this assignment you’ll build a static file server with a little help from Express.
- Time: 4:00h
- Goals: subgoal 3, subgoal 4
- Due: before week 3
We'll add more features to our server. It should handle routes and serve static files. Make sure it does (atleast) the following three things:
- Basic routing: Have a couple of different
routes
(e.g./about
/login
) that are useful for your matching-application. - Error handling: Respond with a
404 Not Found
if you go to a route that doesn't exist. - Serve
static files
: such CSS but also media files such as images, video's or audio files.
Ask yourself upon completion:
- How does the
app instance
work? What makes it possible you can do things likeapp.get
orapp.listen
? - What are the
req
andres
parameters?
Additional resources
Learn how to use a templating engine to dynamically render data and create components for your matching application.
- Time: 6:00h
- Goals: subgoal 4
- Due: before week 3
We are slowly going to build the interface and components for your matching application. You already have a server up an running, now it's time to actually send dynamic HTML to the client using a templating engine.
- Research different templating engines and read there documentation such as
pug
,ejs
. Document your research in your wiki. Pick one, explain why you chose it, and install it in your project.
💡 Some templating engines can be a little bit hard to set-up (looking at you 👀 handlebars). So carefully read their documentation and try out a couple of different ones. If you can't get yours working, look for students who are working with the same templating engine.
-
Then, create views and try to render a page using the templating engine. Start with 'simple' HTML pages and make sure you get different .html for each route.
-
Then, render dynamic data using your templating engine. So instead of you writing the .html insert some dynamic data. For example; you can store and array or object on the server and inject data into the view. Later we'll look at how to insert data from a database.
-
Use the features of your templating engine. Try out atleast the following:
- Use
includes
; to insert contents of files into another. - Use
conditionals
; if statements to render html conditionally - Use
mixins
; create small reusable blocks of html
- Use
-
Start building out your components for your matching application feature. You can create different partials and lay-outs (includes) for components of your page e.g. header, footer or a form.
💡 It's very common to create a consistent naming convention and folder structure for your components. Most people base it on the Atomic Design method by Brad Frost. Here's an example with different partials and lay-out components.
Ask yourself upon completion:
- How does express combine the data from the server with the templating engine?
- How do partials work? Can you create a folder structure for all the components?
Additional resources
-
Push your changes:
Commit your progess in your repository on GitHub under your username in your own matching-app repository. -
Create an issue:
Mark this assignment as complete by opening an issue on our GitHub issue tracker. Fill in the issue template ofweek-2.md
with the correct information. Include what progress you made in the description of the issue. -
Feedback:
Let us know what you thought of the homework, what part you spend a lot of time on and give us any feedback. Your assignment will be reviewed by teachers and student assistants, so expect people to read it and be ready for tips and tops!