express.js Flashcards
What is the appropriate Content-type header for HTTP messages that contain JSON in their bodies?
application/json; charset=utf-8
What does the express.json() middleware do and when would you need it?
*parses incoming json bodies and attaches them as the body property of the res object.
What is the significance of an HTTP request’s method?
It requests certain functionalities and for each one, it will only affect the server in the way it was implied by the method…?
* to make it semantically coherent
404 = not found
200(something) = success
How do you add express to your package dependencies?
Create a new package.json using the npm init command
Use npm to install express (npm install express)
What Express application method starts the server and binds it to a network PORT?
The .listen() method
How do you mount a middleware with an Express application?
By using the use method on the app object
Then calling it with a callback function called with req, res, next
Call send method of the res object called with a string
Which objects does an Express application pass to your middleware to manage the request/response lifecycle of the server?
Request object and response object
Req, res, next
If the current middleware function does not end the request-response cycle, it must call next() to pass control to the next middleware function. Otherwise, the request will be left hanging.
Middleware?
functionality you put in between things (takes in the req and res)