Skip to content

Class 2 notes#17

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

Class 2 notes#17
Somanath1786 wants to merge 1 commit intopce-uw-jscript400:masterfrom
Somanath1786:master

Conversation

@Somanath1786
Copy link

No description provided.


* **Your Answer:**
* **Your Answer:** Anything that follows the ? in the GET request is a query param. After the question mark is a key value pair and if you want to send in more key value pairs you combine them using &

Copy link

Choose a reason for hiding this comment

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

👍

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

* **Your Answer:**
* **Your Answer:** Everytime a request is made
Copy link

Choose a reason for hiding this comment

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

Remember in general app.use() only fires when a request reaches that line in the route chain.

* **Question:** The above can be described as middleware. Describe what middleware is in your own words and how it differs from building a route.

* **Your Answer:**
* **Your Answer:** middleware is something that acts as a wrapper and exposes many methods within app for easy access. Without middleware we can still build the entire server but just that the code will tend to be overly verbose. middleware acts as a translation unit and makes life easier by providing useful wrappers
Copy link

Choose a reason for hiding this comment

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

Middleware is the code/application/module that communicates between two systems, such as between servers and databases. The code above is different than a route because it is always run whenever the application gets to these lines.


* **Your Answer:**
* **Your Answer:** if a particular path was not found for any of the req methods like get post put etc ,we log out the error messages using these app.use statements

Copy link

Choose a reason for hiding this comment

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

Correct, the First catches any missed requests that do not match routes, the second returns an error message.

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