Mayank Agarwal

Mayank Agarwal

307 Articles Published

Articles by Mayank Agarwal

Page 16 of 31

res.attachment() Method in Express.js

Mayank Agarwal
Mayank Agarwal
Updated on 29-Jan-2022 1K+ 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" and copy the following code snippet. After creating the file, use the command "node resAttachment.js" to run this code as shown in the example below −// res.attachment() Method Demo Example // Importing the express var express = require('express'); // Initializing the express and port number var app = ...

Read More

req.params Property in Express.js

Mayank Agarwal
Mayank Agarwal
Updated on 29-Jan-2022 9K+ 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" and copy the following code snippet. After creating the file, use the command "node reqParams.js" to run this code as shown in the example below −// req.params Property Demo Example // Importing the express var express = require('express'); // Initializing the express and port number var app = ...

Read More

req.route Property in Express.js

Mayank Agarwal
Mayank Agarwal
Updated on 29-Jan-2022 429 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 // Importing the express module var express = require('express'); // Initializing the express and port number var app = express(); // Initializing the router from express var router = express.Router(); var PORT = 3000; // Defining an endpoint and checking req.route app.get('/api', function (req, res) { ...

Read More

res.location() Method in Express.js

Mayank Agarwal
Mayank Agarwal
Updated on 29-Jan-2022 947 Views

The res.location() method is used for setting the response Location HTTP header to the specified path parameter. Setting the location does not end the process, one can still send some response after setting the location header.Syntaxres.location( path )Example 1Create a file with the name "resLocation.js" and copy the following code snippet. After creating the file, use the command "node resLocation.js" to run this code as shown in the example below −// res.location(path) Method Demo Example // Importing the express module var express = require('express'); // Initializing the express and port number var app = express(); // Initializing ...

Read More

req.protocol Property in Express.js

Mayank Agarwal
Mayank Agarwal
Updated on 29-Jan-2022 686 Views

The req.protocol property returns the request protocol string that is either http or (for TLS requests) https. The value of X-Forwarded-Proto header field is used if present, when the passed trust proxy setting does not evaluate to False. This header values can be set either by the client or by the proxy.Syntaxreq.protocolExample 1Create a file with the name "reqProtocol.js" and copy the following code snippet. After creating the file, use the command "node reqProtocol.js" to run this code as shown in the example below −// req.protocol Property Demo Example // Importing the express module var express = require('express'); ...

Read More

res.links() Method in Express.js

Mayank Agarwal
Mayank Agarwal
Updated on 29-Jan-2022 597 Views

The res.links() method is used for joining two links that are provided as properties of the parameter to populate the response’s Link HTTP header value.Syntaxres.links( links )Example 1Create a file with the name "resLinks.js" and copy the following code snippet. After creating the file, use the command "node resLinks.js" to run this code as shown in the example below −// res.links(links) Method Demo Example // Importing the express module var express = require('express'); // Initializing the express and port number var app = express(); // Initializing the router from express var router = express.Router(); var PORT = ...

Read More

router.use() Method in Express.js

Mayank Agarwal
Mayank Agarwal
Updated on 29-Jan-2022 2K+ Views

The router.use() method has an optional mount path which is set to "/" by default. This method uses the specified middleware functions for this optional mountpath. The method is similar to app.use().Syntaxrouter.use( [path], [function, ...] callback )Example 1Create a file with the name "routerUse.js" and copy the following code snippet. After creating the file, use the command "node routerUse.js" to run this code as shown in the example below:// router.use() Method Demo Example // Importing the express module const express = require('express'); // Initializing the express and port number var app = express(); // Initializing the router ...

Read More

res.vary() Method in Express.js

Mayank Agarwal
Mayank Agarwal
Updated on 29-Jan-2022 408 Views

The res.vary() method can be used for adding the field to the Vary response header, if the field does not already exist there. The vary header is basically used for content negotiation.Syntaxres.vary( field )Example 1Create a file with the name "resVary.js" and copy the following code snippet. After creating the file, use the command "node resVary.js" to run this code as shown in the example below −// res.vary() Method Demo Example // Importing the express module var express = require('express'); // Initializing the express and port number var app = express(); // Initializing the router from express ...

Read More

req.hostname Property in Express.js

Mayank Agarwal
Mayank Agarwal
Updated on 29-Jan-2022 2K+ Views

The req.hostname contains the hostname that is derived from the host HTTP header. This property will get its value from the X-Forwarded-Host header field when the trust setting properties are enabled (or not set to false). This header can be set by the client or by the proxy.The value of the first header is used if more than one X-Forwarded-Host headers are there in the request.Syntaxreq.hostnameExample 1Create a file with the name "reqHostname.js" and copy the following code snippet. After creating the file, use the command "node reqHostname.js" to run this code as shown in the example below −// req.hostname ...

Read More

req.fresh Property in Express.js

Mayank Agarwal
Mayank Agarwal
Updated on 29-Jan-2022 368 Views

The req.fresh property returns True or false based upon the status of the client's cache. If the cache is still fresh, True is returned, else False will be returned to indicate that the cache is stale and all the content needs to be sent instead of just non-cached part.When a client sends the Cache-Control as no-cache request header to indicate an end-to-end reload request, False will be returned to make the handling of these requests transparent.Syntaxreq.freshExample 1Create a file with the name "reqFresh.js" and copy the following code snippet. After creating the file, use the command "node reqFresh.js" to run ...

Read More
Showing 151–160 of 307 articles
« Prev 1 14 15 16 17 18 31 Next »
Advertisements