-
Notifications
You must be signed in to change notification settings - Fork 0
Lesson 03 Introduction to Express
This lesson introduces Express, and shows how to do simple web serving within the Express framework. Only the get operation is used. On completion of this lesson, students should know the basic boilerplate necessary to bring up an Express web server. It is a good idea to go through each of these elements. The working directory for the students is 02-express-tutorial, and examples are in the final directory. The students create an app.js in the main directory, plus public/index.html. This is the first of two lessons introducing Express.
Note that there is an optional assignment in the node-express-course/week_3_alt_assignment directory. Students completing their assignment may wish to review their submission with a mentor.
It is a good idea to go through these concepts. HTTP headers are not described in the assignment, but it is a good idea to go over them, esp. the content-type header. Here are some suggested questions.
- What are the HTTP verbs, and why are they useful?
- When you visit a website, which HTTP verb does the browser use?
- How are HTTP headers used?
- What does the content-type header do? (this question is taught explicitly in this lesson; students should know)
- Alternatively, you can comment on part 4, where we use
express.staticand ask what happened to all of the complexity of content-type headers from part 3? (answer: express sets the content-type automatically based on the file extension)
- Alternatively, you can comment on part 4, where we use
- Are HTTP headers placed on the request, the response, or both?
Students may have some trouble assembling the required app.js server. In particular, the format of the app.get statement may be confusing, in that one must pass a function that is called when a get statement for a particular path is received. Emphasize the ordering of the statements in app.js. Explain the use of parameters from the path, and the query string. Discuss JSON as needed.