Express Flashcards

1
Q

How do you add express to your package dependencies?

A

‘Npm install express’ into the terminal while in the package directory

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, takes the port number and a cb function

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

Is a computer a server?

A

Well… sort of. It runs the program the provides a service, but the computer itself is not a server.

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

Regarding HTTP status messages, what are the general categories for 100, 200, 300, 400, and 500 response codes?

A

100s —> informational responses
200s —> successful responses
300s —> redirection messages
400s —> client error responses
500s —> server error responses

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

How do you mount a middleware with an Express application?

A

When calling the use method, pass in the mount path as a parameter before the cb function

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

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

A

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).

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

What is the difference between front end and back end code?

A

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

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

The first request a browser makes is for a…

A

Index.html page
Within the index.html, there are lots of other requests (css, js, images, etc.)

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

Middleware is just a fancy name for a…

A

Function that does something between two other things — in this case request and response

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

What is a RESTful API?

A

They use a path to determine the specific resource, and a method to dictate the action on that resource

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

Paths pretty much always start with…

A

/api —> This helps distinguish the front end and back end routing

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

App.use is a ‘weak’ match — what does that mean?

A

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( )

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

When we’re defining specific routes, we use other methods, like…

A

App.post, app.get, app.patch, etc.

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

Once we send a response, can we send another response?

A

Nope —> you can only send one response per request.

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

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

A

It shows the intent of what the request should do.

17
Q

How do you represent a parameter in the path?

A

Use ‘:parameter-name’

18
Q

How do you access path parameters inside of its code block?

A

Use ‘req.params’ to get all parameters with :’parameter-name’ as the key and passed in data as the value

Can also use ‘req.params.’parameter-name’ to get a specific parameter

19
Q

Status code 204 is for…

A

No content. Cannot send data after sending this status code.

20
Q

The property name in the params object is determined by…

A

:’parameter-name’ in the path

21
Q

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

A

It parses incoming requests with JSON data —> it populates the parsed data on the request object if successful (as req.object). Useful when you need to parse data into an object.

22
Q

If you see body:undefined in the console where your server is running, what’s the issue?

A

You probably forgot to add the jsonMiddleware —> app.use(express.json( ))

23
Q

What creates req.body?

A

It’s created by the json Middleware, and it assigns any JSON data in the request into an object

24
Q

If you add a colon to the request arguments, what is the result?

A

score:=72 —> sends a number (72)

25
Q

What is the default status code?

A

200

26
Q

What status code do we use for post and what method do we typically chain on?

A

201.json(data-to-send)

27
Q

What does Express.static return?

A

A middleware function serveStatic —> serves files from the directory (path) passed into express.static

28
Q

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

A

The directory name of the current module.

29
Q

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

A

It joins all given path segments together into a beautiful final path that is OS specific (YEET)

30
Q

What loads into the browser first?

A

The index.html document —> then the browser makes additional requests from there

31
Q

StaticMiddleware is typically one of the first on your server —> why?

A

Any files that need loaded on the page should come first!