express.js Flashcards

1
Q

What is the appropriate Content-type header for HTTP messages that contain JSON in their bodies?

A

application/json; charset=utf-8

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
2
Q

What does the express.json() middleware do and when would you need it?

A

*parses incoming json bodies and attaches them as the body property of the res object.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
3
Q

What is the significance of an HTTP request’s method?

A

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 well did you know this?
1
Not at all
2
3
4
5
Perfectly
4
Q

How do you add express to your package dependencies?

A

Create a new package.json using the npm init command

Use npm to install express (npm install express)

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
5
Q

What Express application method starts the server and binds it to a network PORT?

A

The .listen() method

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
6
Q

How do you mount a middleware with an Express application?

A

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

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
7
Q

Which objects does an Express application pass to your middleware to manage the request/response lifecycle of the server?

A

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.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
8
Q

Middleware?

A

functionality you put in between things (takes in the req and res)

How well did you know this?
1
Not at all
2
3
4
5
Perfectly