Found 33676 Articles for Programming

Express.js – res.set() Method

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

974 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 – req.is() Method

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

484 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 type parameter takes the input for the Content-type to be matched. For example, html, text/html, text/*, etc.Example 1Create a file with the name "req.js" and copy the following code snippet. After creating the file, use the command "node req.js" to run this code as shown in the example below −// ... Read More

Express.js – Getting Remote Client Address

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

240 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
Updated on 28-Mar-2022 11:58:23

528 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
Updated on 28-Mar-2022 11:54:55

248 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

What are the differences between DTD and XSD?

Bhanu Priya
Updated on 17-Mar-2022 10:56:57

1K+ Views

Let us understand the concepts of XML Schema Definition (XSD) and Document Type Definition (DTD) before learning the differences between them.XML Schema Definition (XSD)XML is called an Extensible markup language which is used for the representation and manipulation of the data elements. It is a language which is used to communicate the data in the form of structures on the internet.XSD is called as XML scheme definition is the more extended version of the data definition language and is used to explain the structure of the XML schema. The XML features are that it explains the document in a more ... Read More

C++ code to count maximum hay-bales on first pile

Arnab Chakraborty
Updated on 15-Mar-2022 07:03:37

159 Views

Suppose we have an array A with n elements and another value d. A farmer has arranged n haybale piles on the firm. The ith pile contains A[i] hay-bales. Every day a cow can choose to move one hay-bale in any pile to an adjacent pile. The cow can do this on a day otherwise do nothing. The cow wants to maximize the hay-bales in first pile in d days. We have to count the maximum number of hay-bales on the first pile.So, if the input is like d = 5; A = [1, 0, 3, 2], then the output ... Read More

C++ code to find name with O's on Fibonacci positions

Arnab Chakraborty
Updated on 15-Mar-2022 07:01:34

125 Views

Suppose we have a number n. Amal wants to give a name to his pet. He will follow an algorithm. The name will be n characters long. The name will contain uppercase and lowercase letters 'O's and 'o's. The algorithm suggests the i-th letter of the name should be 'O' (uppercase) if i is a member of Fibonacci sequence, and 'o' (lowercase) otherwise. The letters in the name are numbered from 1 to n.So, if the input is like n = 10, then the output will be "OOOoOooOoo", because first fibonacci numbers are 1, 2, 3, 5 and so on.StepsTo ... Read More

C++ code to find position of students after coding contest

Arnab Chakraborty
Updated on 15-Mar-2022 06:58:57

380 Views

Suppose we have an array A with n elements. In a coding contest, in total n students will participate, and before the start, every one of them has some positive rating (integer). A[i] represents the rating of ith student. After the contest ends, every student will end up with some positive integer position. We are expecting the students will take places according to their ratings. If student A has rating strictly lower than student B, A will get strictly greater position than B. We have to find the position at the end of the contest.So, if the input is like ... Read More

C++ code to find tree height after n days

Arnab Chakraborty
Updated on 15-Mar-2022 06:56:23

236 Views

Suppose we have an array A with n elements. A has elements either 0 or 1. There is a tree. In consecutive n days, if A[i] is 0 it is not watered, if it is 1 then it is watered, the flower grows in the following manner −If the tree is not watered for consecutive two days, it diesIf the tree is watered on ith day, it grows 1 cmIf the tree is watered on ith and (i+1)th day consecutively, it grows 5 cm instead of 1 cm.If it is not watered on ith day, it will not grow.At the ... Read More

Advertisements