express-hello-world Flashcards

1
Q

How do you mount a middleware with an Express application?

A

Using the “.use” method on the express application and passing in a path, callback function or both.

Ex: app.use (function (req, res) {
res.send(‘Hello, world!’);
});

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

The request object (req) and the response object (res).
The request object has information about the request but also has methods for dealing with the request.
The response object handles the response and has methods for handling the response such as attaching information to the response and the res.send method, which cuts off the header and sends the body. The parameter passed into the res.send method can be a Buffer object, a string, an object, Boolean or an Array.

  • The middleware function is also usually passed in a “next” middleware function commonly denoted by a variable named “next” to pass control to the next middleware function, if the request-response cycle isn’t ended.
How well did you know this?
1
Not at all
2
3
4
5
Perfectly