Express.js Flashcards

1
Q

How do you add express to your package dependencies?

A

Npm install express

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

How do you mount a middleware with an Express application?

A

The .use() method

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

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

A

The response, and requests

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

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

A

Content type: application/json for JSON

content type: text/html for text

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

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

A

To define the action between the client and the server

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

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

A
  1. It parses the request body

2. When the client is sending a JSON body and you care about it

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

What does express.static() return?

A

a middleware function

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

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

A

an absolute path to the directory that the module is in starting from the root

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

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

A

it joins the paths given as arguments and assigns respective “/”

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

What is the practical utility of express.static() in the web development world?

A

so you don’t have to define get methods for every single file you want to display

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

What is the purpose of making a duplicate .env file from .env.example?

A

ENV = environment variables file

adds environmental objects as properties of process.env object when you require dotenv

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

What is the significance of using “next” as a parameter when defining a network request callback definition?

A
  1. to tell express to short circuit to error middleware

2. to tell the express framework to go to the next middleware

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

why did we previously have to use console.error(error) but now it’s appropriate to use throw ClientError?

A

because error middleware is installed

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