Mayank Agarwal

Mayank Agarwal

307 Articles Published

Articles by Mayank Agarwal

Page 15 of 31

Express.js – res.get() Method

Mayank Agarwal
Mayank Agarwal
Updated on 28-Mar-2022 581 Views

The res.get() method is used to return the HTTP headers specified by the field. The match is case-insensitive and therefore returns all the matching patterns.Syntaxres.get( field )Example 1Create a file with the name "resGet.js" and copy the following code snippet. After creating the file, use the command "node resGet.js" to run this code as shown in the example below −// res.get(field) 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 = 3000; ...

Read More

Express.js – req.range() Method

Mayank Agarwal
Mayank Agarwal
Updated on 28-Mar-2022 668 Views

req.range() is basically a range header parser. The accept-ranges and the response-header fields allow the server to indicate the acceptance of the range requests from a resource.Syntaxreq.range( size, [options])ParametersThe above parameters are defined as follows −size – The size parameter defines the maximum size of the resource.options – The options parameter can have the following properties −combine – It is a Boolean type variable. This parameter specifies if overlapping and whether the adjacent ranges should be combined or not. Default: FalseExample 1Create a file with the name "reqRange.js" and copy the following code snippet. After creating the file, use the ...

Read More

Express.js – req.xhr Property

Mayank Agarwal
Mayank Agarwal
Updated on 28-Mar-2022 645 Views

The req.xhr property is a Boolean property that returns True when the request's X-Requested-With header field is "XMLHttpRequest". The True pointer basically indicates that the request was issued by a client library such as jQuery.Syntaxreq.xhrExample 1Create a file with the name "reqXhr.js" and copy the following code snippet. After creating the file, use the command "node reqXhr.js" to run this code as shown in the example below −// req.xhr Property Demo Example // Importing the express module var express = require('express'); // Initializing the express and port number var app = express(); // Initializing the router from ...

Read More

Express.js – req.stale Property

Mayank Agarwal
Mayank Agarwal
Updated on 28-Mar-2022 279 Views

The req.stale property checks whether a request is fresh or stale in the client's cache. If the property returns True, it means the client's cache is stale and all the data needs to be transferred to the client's system. Else, only the non-cached data needs to be transmitted.Syntaxreq.staleExample 1Create a file with the name "reqStale.js" and copy the following code snippet. After creating the file, use the command "node reqStale.js" to run this code as shown in the example below −// req.stale Property Demo Example // Importing the express var express = require('express'); // Initializing the express and ...

Read More

Express.js – req.secure Property

Mayank Agarwal
Mayank Agarwal
Updated on 28-Mar-2022 273 Views

The req.secure property returns a Boolean value that returns true if a TLS connection is established, else it will return False.Its logic is similar to the following method −--> req.protocol == "https"Syntaxreq.secureExample 1Create a file with the name "reqSecure.js" and copy the following code snippet. After creating the file, use the command "node reqSecure.js" to run this code as shown in the example below −// req.secure Property Demo Example // Importing the express var express = require('express'); // Initializing the express and port number var app = express(); // Initializing the router from express var router = ...

Read More

Express.js – res.set() Method

Mayank Agarwal
Mayank Agarwal
Updated on 28-Mar-2022 1K+ 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, use the command "node resSet.js" to run this code as shown in the example below −// res.set(field, [value]) Method Demo Example // Importing the express var express = require('express'); // Initializing the express and port number var app = express(); // Initializing the router from express var ...

Read More

Express.js – Getting Remote Client Address

Mayank Agarwal
Mayank Agarwal
Updated on 28-Mar-2022 315 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 proxy isn't yours, one should be careful while using the x-forwarded-for header, because it can be spoofed.Example 1Create a file with the name "remoteAddress.js" and copy the following code snippet. After creating the file, use the command "node remoteAddress.js" to run this code as shown in the example below −// ...

Read More

Express.js – res.jsonp() Method

Mayank Agarwal
Mayank Agarwal
Updated on 28-Mar-2022 574 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, use the command "node resJsonp.js" to run this code as shown in the example below −// res.jsonp([body]) 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 ...

Read More

Express.js – app.disabled() Method

Mayank Agarwal
Mayank Agarwal
Updated on 28-Mar-2022 301 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, use the command "node appDisabled.js" to run this code as shown in the example below −// app.disabled() Method Demo Example // Importing the express module const express = require('express'); // Initializing the express and port number var app = express(); // Initializing the router from express var ...

Read More

req.method Property in Express.js

Mayank Agarwal
Mayank Agarwal
Updated on 29-Jan-2022 1K+ 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 the following code snippet. After creating the file, use the command "node reqMethod.js" to run this code as shown in the example below −// req.method Property Demo Example // Importing the express & cookieParser module var cookieParser = require('cookie-parser'); var express = require('express'); // Initializing the express and ...

Read More
Showing 141–150 of 307 articles
« Prev 1 13 14 15 16 17 31 Next »
Advertisements