W4 Flashcards
app.locals
- allows you to attach local variables to the application, which persist throughout the life of the app
app.all()
This method will catch all HTTP requests for all verbs. IE: GET, PUT, POST, DELETE, etc. for a matching path.
app.delete()
Routes a HTTP DELETE request for a matching path to a callback function specified.
app.engine()
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.
app.get()
Routes a HTTP GET request for a matching path to a callback function specified.
app.listen()
- 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.
app.post()
Routes a HTTP POST request for a matching path to a callback function specified.
app.put()
Routes a HTTP PUT request for a matching path to a callback function specified.
app.use()
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.
req.body
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.
req.cookies
If you are using a cookie and you use cookie parsing middleware, then the cookie data will be available on the req.cookie object.
req.params
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).
req.query
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.
req.get
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.
res.cookie()
allows you to set a cookie on the response with a name = value key pair.