Skip to content

in-class questions and answers#18

Open
scl9087 wants to merge 1 commit intopce-uw-jscript400:masterfrom
scl9087:master
Open

in-class questions and answers#18
scl9087 wants to merge 1 commit intopce-uw-jscript400:masterfrom
scl9087:master

Conversation

@scl9087
Copy link

@scl9087 scl9087 commented Jul 10, 2019

No description provided.

* **Question:** When does `app.use()` get called?

* **Your Answer:**
* **Your Answer:** It is used to setup every middleware you want to use. It can be called generically or when specific paths are specified.
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

app.use() will always be called once a request reaches that point of the route chain.

* **Question:** What type of thing is `app` and what is its purpose?

* **Your Answer:**
* **Your Answer:** App is an event emitter and function used to start the express server.
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

👍

* **Question:** What type of thing is `next` and what does it represent in the callback?

* **Your Answer:**
* **Your Answer:** "next" specifies the next function in the callback.
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

continues to the next matching route


* **Question:** Try creating a new vegetable. Then, try restarting your server. What happens to the data you posted and why?

* **Your Answer:**
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Data does not persist after sever is restarted since it is not saved to a file or database

* **Question:** Take a look at the last two `app.use()` methods at the end of the file. Describe how both work and what `err` is refers to.

* **Your Answer:**
* **Your Answer:** The last app.use() is a error handler function that acts as a catch-all.
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Correct, the second to last app.use() will catch any unmatched requests and format an error.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants