W4 Flashcards

1
Q

app.locals

A
  • allows you to attach local variables to the application, which persist throughout the life of the app
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
2
Q

app.all()

A

This method will catch all HTTP requests for all verbs. IE: GET, PUT, POST, DELETE, etc. for a matching path.

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

app.delete()

A

Routes a HTTP DELETE request for a matching path to a callback function specified.

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

app.engine()

A

used to map a specific view extension to a template engine. For example if you want to map all html view templates to a specific engine you would register it here.

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

app.get()

A

Routes a HTTP GET request for a matching path to a callback function specified.

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

app.listen()

A
  • typically called once to setup a port and optionally a host to listen on for requests.
  • helps setup a https server and allows it to listen on a specified port. HTTP default port is 80, HTTPS default port is 443.
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
7
Q

app.post()

A

Routes a HTTP POST request for a matching path to a callback function specified.

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

app.put()

A

Routes a HTTP PUT request for a matching path to a callback function specified.

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

app.use()

A

used to add middleware to your application. Middleware consists of functions (typically placed before the routing methods) that automatically execute either when a specified path is matched or globally before every request.

  • very useful when you want to do something with every request like add properties to the request object or check if a user is logged in.
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
10
Q

req.body

A

The req.body property contains the data submitted from a request.

  • requires that you use a body parsing middleware first which will attach the parameters to req.body. If you post data in your request then this is how you access that data.
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
11
Q

req.cookies

A

If you are using a cookie and you use cookie parsing middleware, then the cookie data will be available on the req.cookie object.

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

req.params

A

The third way of sending data is in the url.

For example, if you want to have a url in the pattern /user/:name where the :name is dynamic; ie: for ‘Bob’ it’s /user/bob and for ‘Mary’ it’s /user/mary.

access each differing username through req.params (ie: request.params.user).

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

req.query

A

If you send data for a user using a url like /user?user=bob then you can access that username with req.query.user. ‘query’ will be an object with key value pairs matching the key value pairs sent in the query string of the request.

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

req.get

A

req.get() is useful for checking what the values are of any of the headers sent with the request. If you need to check the ‘content-type’ for example or the ‘referer’ or ‘user-agent’ headers.

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

res.cookie()

A

allows you to set a cookie on the response with a name = value key pair.

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

res.download()

A

allows you to send a file back as a response

17
Q

res.end()

A

end a response immediately and send nothing back. You can also chain .end() off of .status to send a status code and end the response, ie: res.status(400).end();

18
Q

res.get()

A

use res.get() to lookup any header that is outgoing on the response.

19
Q

res.json()

A

send back a JSON object with key value pairs of data.

20
Q

res.redirect()

A

Use this to perform a redirect to another page on your site, go back to the previous page, or redirect to another domain all together.

21
Q

res.send()

A

You can send a String, an object, an Array, or even a Buffer object back to the client. The send() method will automatically set the Content-Type header for you based on the type of data sent.

22
Q

res.status()

A

You can use this to send back a specific status code and appropriate response to go with it. status() is chainable before a send() so you can do operations such as: res.status(404).send(“Page Not Found”)

23
Q

What is a route?

A

a path on your site that can have requests sent to it, and respond from it

24
Q

function to send static files

A

app.use(express.static(“static”));