Javascript Articles

Page 174 of 534

Finding longest consecutive joins in JavaScript

AmitDiwan
AmitDiwan
Updated on 15-Mar-2026 202 Views

We are required to write a JavaScript function that takes in an array of pairs of numbers, arr, as the first and the only argument. In every pair, the first number is always smaller than the second number. Now, we define a pair (c, d) that can follow another pair (a, b) if and only if b < c. Chain of pairs can be formed in this fashion. Our function is supposed to find the length longest chain which can be formed. Problem Example For example, if the input to the function is: const arr ...

Read More

Maximum average of a specific length of subarray in JavaScript

AmitDiwan
AmitDiwan
Updated on 15-Mar-2026 196 Views

Problem We are required to write a JavaScript function that takes in an array of integers, arr, as the first argument and a number, num, as the second argument. Our function should find the contiguous subarray of given length num that has the maximum average value. And we need to output the maximum average value. Example Input and Output For example, if the input to the function is: const arr = [1, 12, -5, -6, 50, 3]; const num = 4; The expected output is: 12.75 Output Explanation: ...

Read More

agent.createConnection() Method in Node.js

Mayank Agarwal
Mayank Agarwal
Updated on 15-Mar-2026 857 Views

The agent.createConnection() method is an interface provided by the Node.js http module. This method produces a socket/stream that can be used for HTTP requests. You can override this method in custom agents for greater flexibility. A socket/stream can be returned either directly from this function or by passing it to the callback. Syntax agent.createConnection(options, [callback]) Parameters The above function accepts the following parameters: options – These options contain the connection details for which the stream has to be created. ...

Read More

Creating an Agent in Node.js

Mayank Agarwal
Mayank Agarwal
Updated on 15-Mar-2026 1K+ Views

In Node.js, an HTTP Agent manages connection pooling for HTTP client requests. You can create a custom agent using the new Agent() constructor to control connection behavior like keep-alive settings and socket limits. Syntax new http.Agent({options}) Parameters The Agent constructor accepts an options object with the following configurable properties: keepAlive – Keeps sockets open for reuse instead of closing them after each request. Default: false ...

Read More

Logging in Node.js

Mayank Agarwal
Mayank Agarwal
Updated on 15-Mar-2026 464 Views

Logging is a very essential part in any application whether it is made in Node.js or any other programming languages. Logging helps us to detect weird behaviours of an application along with real-time errors and exceptions. One should definitely put logical logs in their application. These logs help the user to identify any mistakes and resolve it on urgent basis. There are 5 different log levels which are present at the moment with the user. These log levels are used to define different kinds of logs and helps the user to identify different scenarios. The log levels must be ...

Read More

crypto.createDiffieHellman() Method in Node.js

Mayank Agarwal
Mayank Agarwal
Updated on 15-Mar-2026 431 Views

The crypto.createDiffieHellman() method in Node.js creates a Diffie-Hellman key exchange object using a specified prime value and an optional generator. This method enables secure key exchange between two parties over an insecure channel. Syntax crypto.createDiffieHellman(prime, [primeEncoding], [generator], [generatorEncoding]) Parameters prime – The prime number used for the Diffie-Hellman exchange. Can be a number (bit length) or Buffer/string containing the prime value. primeEncoding ...

Read More

crypto.createHash() Method in Node.js

Mayank Agarwal
Mayank Agarwal
Updated on 15-Mar-2026 3K+ Views

The crypto.createHash() method creates a hash object that can generate hash digests using cryptographic algorithms like SHA-256, MD5, or SHA-512. It's commonly used for password hashing, data integrity verification, and digital signatures. Syntax crypto.createHash(algorithm, [options]) Parameters algorithm – The hashing algorithm to use (string). Common values: 'sha256', 'md5', 'sha512', 'sha1' options – Optional parameters for controlling stream behavior and output length for certain algorithms Return Value Returns a Hash object that can be used to generate hash digests by chaining update() and digest() methods. Example 1: Basic Hash Generation ...

Read More

crypto.createHmac() Method in Node.js

Mayank Agarwal
Mayank Agarwal
Updated on 15-Mar-2026 3K+ Views

The crypto.createHmac() method creates and returns an HMAC (Hash-based Message Authentication Code) object in Node.js. This method uses a specified algorithm and secret key to generate cryptographic hashes for data integrity and authentication purposes. Syntax crypto.createHmac(algorithm, key, [options]) Parameters algorithm – The hashing algorithm to use (e.g., 'sha256', 'sha1', 'md5'). Input type is string. key – The secret key used for generating the cryptographic HMAC hash. Can be a string, Buffer, TypedArray, or DataView. options – Optional parameters for controlling stream ...

Read More

crypto.pbkdf2() Method in Node.js

Mayank Agarwal
Mayank Agarwal
Updated on 15-Mar-2026 2K+ Views

The crypto.pbkdf2() method in Node.js implements the Password-Based Key Derivation Function 2 (PBKDF2) algorithm. It derives a cryptographic key from a password using a salt and multiple iterations to enhance security against brute-force attacks. Syntax crypto.pbkdf2(password, salt, iterations, keylen, digest, callback) Parameters The parameters are described as follows: password – The password string used for key derivation. Accepts string, Buffer, TypedArray, or DataView. ...

Read More

agent.maxFreeSockets Property in Node.js

Mayank Agarwal
Mayank Agarwal
Updated on 15-Mar-2026 562 Views

The agent.maxFreeSockets property defines the maximum number of sockets that can be kept open in the free state for connection reuse. This is part of Node.js HTTP agent configuration and helps optimize HTTP connection pooling. Syntax agent.maxFreeSockets = number Parameters number – Specifies the maximum number of sockets that can remain open in the free state. Default value is 256. Understanding Free Sockets Free sockets are HTTP connections that have completed their current request but remain open for potential reuse. This improves performance by avoiding the overhead of establishing new ...

Read More
Showing 1731–1740 of 5,340 articles
« Prev 1 172 173 174 175 176 534 Next »
Advertisements