Express Flashcards

1
Q

How do you mount a middleware with an Express application?

A

app.use()

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

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

A

A request object (req)
A response object (res)
A next object (next)

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

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

A

application/json

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

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

A

It’s used to parse incoming requests with a JSON body and assign the parsed data to req.body and one would need it when passing JSON objects to the server for some form of processing

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

What does express.static() return?

A

It returns a middleware function that serves static files.

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

What is the local __dirname variable in a Node.js module?

A

It is a local variable that returns the directory name of the current module. It returns the folder path of the current JavaScript file.

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

What does the join() method of Node’s path module do?

A

It joins together path segments together, normalizes them, and then returns the resulting path.

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