Open In App

Express.js Request Complete Reference

Last Updated : 01 Nov, 2023
Like Article

Express.js is a small framework that works on top of Node.js web server functionality to simplify its APIs and add helpful new features. It makes it easier to organize your application’s functionality with middleware and routing.

Express.js Request Properties:



Express.js Property

The property holds the reference to the instance of the Express application that is using the middleware.

Express.js req.baseUrl Property

The req.baseUrl property is the URL path on which a router instance was mounted. The req.baseUrl property is similar to the mount path property of the app object, except app.mountpath returns the matched path pattern(s).

Express.js req.body Property

The req.body property contains key-value pairs of data submitted in the request body. By default, it is undefined and is populated when you use a middleware called body-parsing such as express.urlencoded() or express.json().

Express.js req.cookies Property

The req.cookies property is used when the user is using cookie-parser middleware. This property is an object that contains cookies sent by the request

Express.js req.fresh Property

The req.fresh property returns true if the response is still ‘fresh’ in the client’s cache else it will return false.

Express.js req.hostname Property

The req.hostname property contains the hostname which is derived from the Host HTTP header. It basically returns the hostname which is being supplied in the host HTTP header.

Express.js req.ip Property

The req.ip property contains the remote IP address of the request. It is useful when the user wants the IP address of the incoming request made to the application.

Express.js req.ips Property

The req.ips property contains an array of IP addresses specified in the X-Forwarded-For request header. It returns an array of IP addresses.

Express.js req.method Property

The req.method property contains a string corresponding to the HTTP method of the request which can be either GET, POST, PUT, DELETE, etc.

Express.js req.originalUrl Property

The req.originalUrl property is much like req.url however, it returns the original request URL thereby allowing you to rewrite req.url freely for internal routing purposes.

Express.js req.params Property

The req.params property is an object containing properties mapped to the named route “parameters”.

Express.js req.path Property

The req.path property contains the path of the request URL. This property is widely used to get the path part of the incoming request URL.

Express.js req.protocol Property

The req.protocol property contains the request protocol string which is either HTTP or (for TLS requests) https. When the trust proxy setting does not evaluate to false, this property will use the X-Forwarded-Proto header field value if it is present.

Express.js req.query Property

The req.query property is an object containing the property for each query string parameter in the route.

Express.js req.route Property

The req.route property contains the currently-matched route which is a string.

Express.js Property

The property is a Boolean property that is true if a TLS connection is established else returns false.

Express.js req.signedCookies Property

The req.signedCookies property contains signed cookies sent by the request, unsigned, and ready for use when using cookie-parser middleware.

Express.js req.stale Property

The req.stale property indicates whether the incoming request is stale, and this property is the opposite of req.fresh property.

Express.js req.subdomains Property

The req.subdomains property contains an array of subdomains in the domain name of the request. The application property subdomain offset, which defaults to 2 determines the beginning of the subdomain segments

Express.js req.xhr Property

The req.xhr property returns a true value if the request’s X-Requested-With header field is XMLHttpRequest which indicates that the request was issued by a client library such as jQuery.

Express.js Request Methods:



Express.js req.accepts() Function

The req.accepts() function checks if the specified content types are acceptable on the basis of the requests Accept HTTP header field.

Express.js req.acceptsCharsets() Function

The req.acceptsCharsets() function returns the first accepted charset of the specified character sets on the basis of the request’s Accept-Charset HTTP header field otherwise it returns false if none of the specified charsets is accepted.

Express.js req.acceptsEncodings() Function

The req.acceptsEncodings() function returns the first accepted encoding of the specified encodings on the basis of the request Accept-Encoding HTTP header field and it returns false if none of the specified encodings is accepted.

Express.js req.acceptsLanguages() Function

The req.acceptsLanguages() function returns the first accepted language of the specified language on the basis of the request that Accept-Language HTTP header field

Express.js req.get() Function

The req.get() function returns the specified HTTP request header field which is a case-insensitive match and the Referrer and Referrer fields are interchangeable.

Express.js Function

The function returns the matching content-type if the incoming request’s ‘Content-Type’

Express.js req.param() Function

The req.params property is an object containing properties mapped to the named route “parameters”.

Express.js req.range() Function

The req.range() function is basically a Range header parser where the Accept-Ranges response-header field allows the server to indicate its acceptance of range requests for a resource

Like Article
Suggest improvement
Share your thoughts in the comments

Similar Reads