In this practice, you will predict the order that Express middleware will be invoked when making a variety of requests.
Take a look at the server/app.js file. This file contains the Express application and the middlewares connected to the application.
In each of the following scenarios, predict what will be logged in the server logs when a request is made.
You might find it helpful to grab some paper and sketch out a flow diagram for the middlewares in server/app.js.
Write down your predictions for each of the following scenarios.
If a client makes a request to GET /
, what will be logged in the server logs
and in what order?
If a client makes a request to GET /other-resource
, what will be logged in
the server logs and in what order?
If a client makes a request to GET /not-found
, what will be logged in the
server logs and in what order?
Now, it is time to run the application and use the browser or Postman to verify your predictions.
cd
into the server folder.
npm install
the dependencies.
Run npm start
to start the server on localhost
port 5000
.
Request each of the urls. If your prediction matches, that's great! If not, that's ok. This is a skill that needs practice. Review your diagram and use your debugging skills to discover what happened. As needed, formulate good questions for your instructors.