Request Object ?

The Request Object
The request object (which is normally passed to a callback, meaning you can name it whatever you want: it is common to name it req or request) starts its life as an instance of http.IncomingMessage, a core Node object. The most useful properties and methods of the request object (all of these methods are added by Express, except for req.headers and req.url, which originate in Node):

An array containing the named route parameters.

Returns the named route parameter, or GET or POST parameters. I recommend avoiding this method.

An object containing querystring parameters (sometimes called GET parameters) as name/value pairs.

An object containing POST parameters. It is so named because POST parameters are passed in the body of the REQUEST, not in the URL like querystring parameters. To make req.body available, you’ll need middleware that can parse the body content type.

Information about the currently matched route. Primarily useful for route debugging.

Objects containing containing cookie values passed from the client.

The request headers received from the client.

A convenience method to determine whether the client accepts a given type or types (optional types can be a single MIME type, such asapplication/json, a comma-delimited list, or an array). This method is of primary interest to those writing public APIs; it is assumed that browsers will always accept HTML by default.

The IP address of the client.

The request path (without protocol, host, port, or querystring).
A convenience method that returns the hostname reported by the client. This information can be spoofed and should not be used for security purposes.

A convenience property that returns true if the request originated from an AJAX call.

The protocol used in making this request (for our purposes, it will either be http or https).
A convenience property that returns true if the connection is secure. Equivalent to req.protocol===’https’.

These properties return the path and querystring (they do not include protocol, host, or port). req.url can be rewritten for internal routing purposes, but req.originalUrl is designed to remain the original request and querystring.

A convenience method that returns an array of the (human) languages the client prefers, in order. This information is parsed from the request header.

More Info : Express.js


My Name is Dileep Singh, Noder, Javascript Lover & NoSql Developer, Fitness Freak, Love to travel new places, learning photography & Music Manic ♯ ♩ ♬

Posted in Express, Node.Js Tagged with: ,