---
# System prepended metadata

title: '2006-FSA Cookie Jar: Express (101 and 201) & Async/Await'

---

# 2006-FSA Cookie Jar: Express (101 and 201) & Async/Await

Put your pending and outstanding questions here 👇
Make the question in H2 tag by using '##'


## If headers have key-value pairs, can you access them the same way you would an object?
- **Answer:** Absolutely. If it looks like an object, smells like an object, it's an object and can be treated as so. When using variables to access a key, use bracket notation. When you know the exact key name, use dot notation.

## What's the -D flag on the curl request to `google.com` in your example?
- **Answer:** Go to your terminal and run `curl --help`, let's search for this flag by holding the `command` button on your keyboard and hitting the `F` key for "find". In a nut shell, the `-D` flag returns the headers. Per curl's help feature, we can even add another argument after `-D` to have those heads saved into a file on our machine. In our lecture example, we left that argument out by passing `-`.
- **Reference:** `curl -D - http://www.google.com`

## Where do you get commands for Express?
- **Answer:** If by "commands" you mean "methods", they are a part of Express (built-in). Please refer to the [documentation](https://expressjs.com/).

## What is happening under-the-hood with Express as it pertains to http request/response data conversion?
- **Question (cont):** +1 from [Daniel] - could you please code it out/demo and compare them step-by-step using the `server` keyword vs. `express()/app()`, as well?
- **Answer 1:** 
    - I need more clarification as to what you mean by "data conversion". **All HTTP messages** are formatted in a way as displayed in the lecture's slide deck:
        - Request line comprised of the request method (i.e. verb - GET, POST, PUT, etc.), URI (i.e. path), and the HTTP version (e.g. HTTP/1.1).
        - Request headers (i.e. name: value pairs)
        - A blank line always separates the header and body
        - Request body (Note: HTTP requests typically won't have a request body if there isn't information to send to the server (e.g. GET requests). However, in the case when we're creating (e.g. POST requests), let's say, a new account on a website then we need to send that user inputted form information to the server via the request body.)
    - Remember, this is represented as a string. Express handles converting it into a format that is easily digestible for us developers. If you're curious about under-the-hood implementation, I think this is a perfect opportunity to explore this by diving into Express documentation, sifting around the `express` directory in your `node_modules` folder, OR trying to implement it on your own using pure JavaScript.
- **Answer 2:** Unfortunately, there isn't time to do a side-by-side live code of the `http` and `express` modules, but I think it's a great idea to use the slide deck as a reference and try it on your own! The code in the slides have all the pieces you need to do exactly that.

## What exactly is a port? Could you go over how request links work again?
- **Answer:** An airport is to a server, as a gate is to a port. In our case of developing on our local machines, our "localhost" is our server, and we're choosing a PORT to listen on for incoming requests (e.g. 3000, 1337, 8080). Here are some articles:
    - https://computer.howstuffworks.com/web-server8.htm
    - https://www.quora.com/What-is-a-server-port-number

## When you invoke next(), how does it know what's next?
- **Answer:** It will continue iterating through our array of endpoints we created using our Express framework incrementally. Think of it as a `for` loop with a reference to `i` and just picks back up at `i++`.

## What would the passed code be doing without the middleware logging/morgan?  Why is morgan/volleyball necessary?
- **Question (cont):** +1 - `morgan` vs. `volleyball`?
-  **Answer:** Simply to log information for us:
    -  Type of request (method/verb)
    -  URI (API endpoint)
    -  [HTTP status code](https://developer.mozilla.org/en-US/docs/Web/HTTP/Status)

## Spread operator for both Array and Object, could we please do a quick walkthrough?
- **Answer:** Please refer to the MDN documentation:
    - [Spread syntax (...)](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Operators/Spread_syntax)
    - Use the sandbox to play around with it.

## What is 'try' and 'catch' on the Async / Await code?
- **Answer:** Please refer to the MDN documentation:
    - [`try...catch`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Statements/try...catch)


