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):

req.params
An array containing the named route parameters.

req.param(name)
Returns the named route parameter, or GET or POST parameters. I recommend avoiding this method.

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

req.body
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.

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

req.cookies/req.signedCookies
Objects containing containing cookie values passed from the client.

req.headers
The request headers received from the client.

req.accepts([types])
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.

req.ip
The IP address of the client.

req.path
The request path (without protocol, host, port, or querystring).

req.host
A convenience method that returns the hostname reported by the client. This information can be spoofed and should not be used for security purposes.

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

req.protocol
The protocol used in making this request (for our purposes, it will either be http or https).

req.secure
A convenience property that returns true if the connection is secure. Equivalent to req.protocol===’https’.

req.url/req.originalUrl
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.

req.acceptedLanguages
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

About

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: ,