Programming Articles

Page 2090 of 2547

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

res.append() Method in Express.js

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

The res.append() method can append a specified value to the HTTP response header field. It creates new headers with the specified values, if it's not already created. The value string can take both a string input or an array.Syntaxres.append( field, [value] )Example 1Create a file with the name "resAppend.js" and copy the following code snippet. After creating the file, use the command "node resAppend.js" to run this code as shown in the example below −// res.append(field, [value]) Method Demo Example // Importing the express module var express = require('express'); // Initializing the express and port number var app ...

Read More

res.app Property in Express.js

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

The res.app property holds a reference to the instance of an Express Application that is being used by the middleware.Syntaxres.appExample 1Create a file with the name "resApp.js" and copy the following code snippet. After creating the file, use the command "node resApp.js" to run this code as shown in the example below −// res.app code Demo Example // Importing the express module var express = require('express'); // Initializing the express and port number var app = express(); var PORT = 3000; // Creating an endpoint app.get('/', function (req, res) { console.log(res.app.get('views')); ...

Read More

req.path Property in Express.js

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

The req.path property contains the path part of the requested URL. This property is widely used to track the incoming requests and their paths. It is mainly used for logging the requests.Syntaxreq.pathExample 1Create a file with the name "reqPath.js" and copy the following code snippet. After creating the file, use the command "node reqPath.js" to run this code as shown in the example below −// req.path Property Demo Example // Importing the express & cookieParser module var cookieParser = require('cookie-parser'); var express = require('express'); // Initializing the express and port number var app = express(); // Initializing ...

Read More

app.enabled() Method in Express.js

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

The app.enabled() method checks whether a setting name property is enabled or not. It basically checks the value of a setting name and returns True if the property value is also True.Syntaxapp.enabled( name )Example 1Create a file with the name "appEnabled.js" and copy the following code snippet. After creating the file, use the command "node appEnabled.js" to run this code as shown in the example below −// app.enabled() 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 ...

Read More

Find the largest twins in given range in C++

sudhir sharma
sudhir sharma
Updated on 28-Jan-2022 262 Views

In this problem, we are given two values lValue and hValue. Our task is to find the largest twins in given range.Two numbers are said to be twin numbers if both of them are prime numbers and the difference between them is 2.Let's take an example to understand the problem, Input : lValue = 65, rValue = 100 Output : 71, 73Solution ApproachA simple solution to the problem is by looping from rValue - 2 to lValue and checking each pair of i and (i+2) for twins and print the first occurred twin.Another Approach is by finding all prime numbers ...

Read More

Find the largest pair sum in an unsorted array in C++

sudhir sharma
sudhir sharma
Updated on 28-Jan-2022 1K+ Views

In this problem, we are given an arr[] consisting of N unsorted elements. Our task is to find the largest pair sum in an unsorted array.We will find a pair whose sum is the maximum.Let's take an example to understand the problem, Input : arr[] = {7, 3, 9, 12, 1} Output : 21Explanation −Pair with largest sum, (9, 12). Sum = 21 Solution ApproachA simple solution to the problem is by making a pair of maximum and second maximum elements of the array.For this we will initialise the max and secondMax elements of the array with the first and ...

Read More

Find the largest number with n set and m unset bits in C++

sudhir sharma
sudhir sharma
Updated on 28-Jan-2022 227 Views

In this problem, we are given two integer values, n and m. Our task is to find the largest number with n set and m unset bits in the binary representation of the number.Let's take an example to understand the problemInput : n = 3, m = 1 Output : 14Explanation −Largest number will have 3 set bits and then 1 unset bit. (1110)2 = 14Solution ApproachA simple solution to the problem is by finding the number consisting of (n+m) set bits. From this number, toggle off the m bits from the end (LSB). To create a number with (n+m) ...

Read More

Find the Largest number with given number of digits and sum of digits in C++

sudhir sharma
sudhir sharma
Updated on 28-Jan-2022 2K+ Views

In this problem, we are given two integer values, N denoting the count of digits of a number and sum denoting the sum of digits of the number. Our task is to find the largest number with given number of digits and sum of digits.Let's take an example to understand the problem, Input : N = 3, sum = 15 Output : 960Solution ApproachA simple approach to solve the problem is by traversing all N digit numbers from the largest to smallest. The find the digit sum numbers, if it's equal to sum return the number.ExampleProgram to illustrate the working ...

Read More
Showing 20891–20900 of 25,466 articles
Advertisements