You should be able to:
- Describe the role of a client, a server, and HTTP
- Describe Express middleware, requests, and responses
- Handle URL
params
in an Express route - Know when and why you would use
app.use
andnext
in your Express app - Explain the purpose of using
async
/await
& Promises
- A HTTP server listens for HTTP requests and sends HTTP responses.
Reference: MDN: What is a web server?
- Store a list of dependencies for the project
- Give the project a name
- Store metadata about the project
- All of the above ☑️
- None of the above
Reference:
- See the section "Properties of a package.json file" here.
- Node: What is the file
package.json
?
- Node web framework for handling requests ☑️
- Provides mechanisms to:
- Write handlers for requests with different HTTP verbs at different URL paths (routes)
- Set common web application settings like the port to use for connecting
- Add additional request processing “middleware” at any point within the request handling pipeline
- Provides mechanisms to:
- JavaScript runtime environment
- JavaScript library for building user interfaces
- An ORM
Reference:
- An example of it could be
app.use
☑️ - It happens between the request and response ☑️
- Only one middleware function can be called per request-response cycle
- An example of it could be
app.get
☑️ - It sometimes runs after the response is sent
Reference:
- Express: Using middleware
- In reference to
app.get
, in this doc, it says, "Express is a routing and middleware web framework that has minimal functionality of its own: An Express application is essentially a series of middleware function calls." Technically, since Express is built on top of and leverages Node, Express sits in between the request and response.
- In reference to
- Express: Writing middleware for use in Express apps
- Express:
app.use()
- A function that receives the request and response objects of an HTTP request/response cycle (i.e.
(req, res, next) => {...}
).
- A function that runs asynchronous code
- A keyword that marks a function as having asynchronous code
- A callback function that executes after an asynchronous operation finishes
- An object that represents the eventual completion of an asynchronous operation and its resulting value ☑️
Reference:
- You can use
await
outside of anasync
function async
functions are not Promises when the return value is not a Promise itself- Inside of an
async
function, the code behaves synchronously ☑️ async
functions are synchronous
Reference: