Article Categories
- All Categories
-
Data Structure
-
Networking
-
RDBMS
-
Operating System
-
Java
-
MS Excel
-
iOS
-
HTML
-
CSS
-
Android
-
Python
-
C Programming
-
C++
-
C#
-
MongoDB
-
MySQL
-
Javascript
-
PHP
-
Economics & Finance
Javascript Articles
Page 174 of 534
Finding longest consecutive joins in JavaScript
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 MoreMaximum average of a specific length of subarray in JavaScript
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 Moreagent.createConnection() Method in Node.js
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 MoreCreating an Agent in Node.js
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 MoreLogging in Node.js
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 Morecrypto.createDiffieHellman() Method in Node.js
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 Morecrypto.createHash() Method in Node.js
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 Morecrypto.createHmac() Method in Node.js
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 Morecrypto.pbkdf2() Method in Node.js
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 Moreagent.maxFreeSockets Property in Node.js
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