Express Flashcards
How do you add express to your package dependencies?
‘Npm install express’ into the terminal while in the package directory
What Express application method starts the server and binds it to a network PORT?
The listen method, takes the port number and a cb function
Is a computer a server?
Well… sort of. It runs the program the provides a service, but the computer itself is not a server.
Regarding HTTP status messages, what are the general categories for 100, 200, 300, 400, and 500 response codes?
100s —> informational responses
200s —> successful responses
300s —> redirection messages
400s —> client error responses
500s —> server error responses
How do you mount a middleware with an Express application?
When calling the use method, pass in the mount path as a parameter before the cb function
Which objects does an Express application pass to your middleware to manage the request / response lifecycle of the server?
The request object (req) and the response object (res). They also have access to the next middleware function in the applications lifecycle (typically via next).
What is the difference between front end and back end code?
Front End: Downloaded onto the users computer (or phone) and then runs on their device. Makes the website look and function the way it does.
Back End: Lives in a centralized location that we control —> typically in the cloud (AWS). Servers receive requests and deliver responses. Typically responses are either data or file(s
The first request a browser makes is for a…
Index.html page
Within the index.html, there are lots of other requests (css, js, images, etc.)
Middleware is just a fancy name for a…
Function that does something between two other things — in this case request and response
What is a RESTful API?
They use a path to determine the specific resource, and a method to dictate the action on that resource
Paths pretty much always start with…
/api —> This helps distinguish the front end and back end routing
App.use is a ‘weak’ match — what does that mean?
Any requests that start with that path will fire send —> it’s not very concrete
Hence, we typically run app.use() on all paths —> for example checking an API key or including express.json( )
When we’re defining specific routes, we use other methods, like…
App.post, app.get, app.patch, etc.
Once we send a response, can we send another response?
Nope —> you can only send one response per request.
What is the appropriate Content-Type header for HTTP messages that contain JSON in their bodies?
Application/json; charset=Utf-8