Using Request Objects

You pass a Request object to a route handler as the first parameter. The Request object provides data and metadata about the request, including the URL, headers, query string, and much more. It allows you to handle a request appropriately in your code.

Table 18.2 lists some of the most commonly used properties and methods available for the Request object.

Image

Table 18.2 Properties and methods of the HTTP Request object

Listing 18.3 shows how to access the various parts of the Request object. The output in Figure 18.2 shows the actual values associated with a GET request.

Listing 18.3 express_request.js: Accessing properties ...

Get Node.js, MongoDB, and AngularJS Web Development now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.