Mayank Agarwal has Published 380 Articles

Express.js – res.set() Method

Mayank Agarwal

Mayank Agarwal

Updated on 28-Mar-2022 12:08:39

751 Views

The res.set() method can be used for setting the response's HTTP header field to value. You can also set multiple fields at once by passing an object as the parameter.Syntaxres.set( field, [value] )Example 1Create a file with the name "resSet.js" and copy the following code snippet. After creating the file, ... Read More

Express.js – req.is() Method

Mayank Agarwal

Mayank Agarwal

Updated on 28-Mar-2022 12:04:40

334 Views

The req.is() method is used for returning the matching content-type. It returns the matching content-type when the incoming request's "Content-type" HTTP header matches with those of the MIME type specified by the type parameter. If the request has no body, then it returns NULL, else it returns False.Syntaxreq.is( type )The ... Read More

Express.js – Getting Remote Client Address

Mayank Agarwal

Mayank Agarwal

Updated on 28-Mar-2022 12:01:45

155 Views

An application needs to maintain the remote client address for managing the number of requests from a computer system and tracking its usage. But sometimes, the server runs behind an NGINX server, so we need to check its forward request. For this purpose, we can use "x-forwarded-for"Syntaxreq.headers['x-forwarded-for'] || req.socket.remoteAddressIf the ... Read More

Express.js – res.jsonp() Method

Mayank Agarwal

Mayank Agarwal

Updated on 28-Mar-2022 11:58:23

430 Views

The res.jsonp() method sends the json response with JSONP support. This method is similar to the res.json() method with the only difference being that it provides the JSONP callback support.Syntaxres.jsonp ( [body] )Example 1Create a file with the name "resJsonp.js" and copy the following code snippet. After creating the file, ... Read More

Express.js – app.disabled() Method

Mayank Agarwal

Mayank Agarwal

Updated on 28-Mar-2022 11:54:55

190 Views

The app.disabled() method checks and returns True if the property name passed is set to False or is disabled. If not, we can disable the property by using the app.disable() method.Syntaxapp.disabled( name )Example 1Create a file with the name "appDisabled.js" and copy the following code snippet. After creating the file, ... Read More

req.method Property in Express.js

Mayank Agarwal

Mayank Agarwal

Updated on 29-Jan-2022 08:42:24

769 Views

The req.method property contains a string that corresponds to the HTTP methods of the request which are GET, POST, PUT, DELETE, and so on...These methods are based upon the requests sent by the user. All the above methods have different use-cases.Syntaxreq.methodExample 1Create a file with the name "reqMethod.js" and copy ... Read More

router.route() Method in Express.js

Mayank Agarwal

Mayank Agarwal

Updated on 29-Jan-2022 08:39:26

1K+ Views

The router.route() method returns the instance of a single route which can be used to handle the HTTP verbs further with the optional middleware. This method can be used to avoid duplicate route naming and therefore the typing errors.Syntaxrouter.route( path )Example 1Create a file with the name "routerRoute.js" and copy ... Read More

res.attachment() Method in Express.js

Mayank Agarwal

Mayank Agarwal

Updated on 29-Jan-2022 08:36:10

989 Views

The res.attachment() method is used for setting the Content-Disposition header field to "attachment". If a filename is passed, then it sets the Content-type based on the extension name that is retrieved from the res.type(). It sets the Content-Disposition "filename" field with the parameter.Syntaxres.attachment()Example 1Create a file with the name "resAttachment.js" ... Read More

req.params Property in Express.js

Mayank Agarwal

Mayank Agarwal

Updated on 29-Jan-2022 08:32:57

7K+ Views

The req.params property is an object that contains the properties which are mapped to the named route "parameters". For example, if you have a route as /api/:name, then the "name" property is available as req.params.name. The default value of this object is {}.Syntaxreq.paramsExample 1Create a file with the name "reqParams.js" ... Read More

req.route Property in Express.js

Mayank Agarwal

Mayank Agarwal

Updated on 29-Jan-2022 08:23:35

275 Views

The req.route property contains the recently matched route in a string format.Syntaxreq.routeExample 1Create a file with the name "reqRoute.js" and copy the following code snippet. After creating the file, use the command "node reqRoute.js" to run this code as shown in the example below −// req.route Property Demo Example ... Read More

Advertisements