async.queue() Method in Node.js

Mayank Agarwal
Updated on 20-May-2021 12:04:02

3K+ Views

The async module provides different functionalities to work with asynchronous JavaScript in a nodejs application. The async.queue() method returns a queue that is further used for concurrent processing of processes i.e. multiple processing of items at a time/instant.Installing and Using async.queue()Step 1 − Run the following command to initialize the node package manager.npm initStep 2 − Installing the async module using the following command.npm install --save asyncStep 3 − Importing the async module using the below statement in your programs .const async = require('async')Syntaxasync.queue('function', 'concurrency value')ParametersThe above parameters are described as below −function – This parameter defines the function that will ... Read More

agent.maxSockets Property in Node.js

Mayank Agarwal
Updated on 20-May-2021 12:00:29

336 Views

The agent.maxSockets property defines the number of sockets that can be concurrently opened by the agent for each origin. By default, this value is set to Infinity. This is also a part of the 'http' module.Syntaxagent.maxSockets: numberParametersThe above function can accept the following Parameters −number – This defines the number of concurrent sockets an agent can have. Its default value is set to Infinity.ExampleCreate a file with name – maxSockets.js and copy the below code snippet. After creating file, use the following command to run this code as shown in the example below:node maxSockets.jsmaxSockets.js// agent.maxSockets method Demo example // Importing ... Read More

agent.maxFreeSockets Property in Node.js

Mayank Agarwal
Updated on 20-May-2021 11:59:46

318 Views

The agent.maxFreeSockets property defines the number of sockets that are left open while in the free state. This is a part of the 'http' module interface.Syntaxagent.maxFreeSockets : numberParametersThe above function can accept the following parameters −number – This defines the number of sockets that can be kept open in the free state. Its default value is set to 256.ExampleCreate a file with name – maxFreeSockets.js and copy the below code snippet. After creating file, use the following command to run this code as shown in the example below −node maxFreeSockets.jsmaxFreeSockets.js −// agent.maxFreeSockets method Demo example // Importing the http & ... Read More

crypto.randomBytes() Method in Node.js

Mayank Agarwal
Updated on 20-May-2021 11:59:03

3K+ Views

The crypto.randomBytes() generates cyprtographically strong pseudo-random data. This method will not be completed until there is sufficient entropy in the bytes created. But even after this it does not takes more than a few milliseconds. This method basically creates a few random bytes which are further used.Syntaxcrypto.randomBytes(size, [callback])ParametersThe above parameters are described as below −size – This argument defines the number of bytes to be generated. Size must not be greater than 2**31 – 1.callback – The callback is called if any error occurs in the method.ExampleCreate a file with name – randomBytes.js and copy the below code snippet. After creating file, ... Read More

crypto.pbkdf2Sync() Method in Node.js

Mayank Agarwal
Updated on 20-May-2021 11:57:51

774 Views

The crypto.pbkdf2Sync(), also known as Password-Based Key Derivation function 2, provides a synchronous implementation of the derivative function. A key is derived by using the Hmac digest of a specified algorithm from password, salt and iterations. This will create the key in a sync process.Syntaxcrypto.createHmac(algorithm, key, [options])ParametersThe above parameters are described as below −password – Password defined for getting key of the requested byte length. Possible values are of type string, DataView, Buffer, etc.salt – Similar to password for getting the key. Possible values are of type string, DataView, Buffer, etc.iterations – Getting the desired key of requested byte length. It accepts ... Read More

crypto.pbkdf2() Method in Node.js

Mayank Agarwal
Updated on 20-May-2021 11:57:19

1K+ Views

The crypto.pbkdf2(), also known as Password-Based Key Derivation function, provides an asynchronous implementation of the derivative function. A key is derived by using the Hmac digest of a specified algorithm from password, salt and iterationsSyntaxcrypto.createHmac(algorithm, key, [options])ParametersThe above parameters are described as below −password – Password defined for getting key of the requested byte length. Possible values are of type string, DataView, Buffer, etc.salt – Similar to password for getting the key. Possible values are of type string, DataView, Buffer, etc.iterations – Getting the desired key of requested byte length. It accepts the value as number.keylen – This is the requested byte length of ... Read More

crypto.createHmac() Method in Node.js

Mayank Agarwal
Updated on 20-May-2021 11:56:45

2K+ Views

The crypto.createHmac() method will create a Hmac object and then return it. THis Hmac uses the passed algorithm and key. The optional options will be used for controlling the stream behaviour. The key defined will be the HMAC key used for generating cryptographic HMAC hash.Syntaxcrypto.createHmac(algorithm, key, [options])ParametersThe above parameters are described as below −algorithm – This algorithm is used for generating the Hmac objects. Input type is string.key – Hmac key used for generating the cryptographic Hmac hash.options – These are optional parameters which can be used for controlling the stream behaviour.encoding – String encoding to use.ExampleCreate a file with name – createHmac.js and ... Read More

crypto.createHash() Method in Node.js

Mayank Agarwal
Updated on 20-May-2021 11:56:11

2K+ Views

The crypto.createHash() method will create a hash object and then return it. THis hash object can be used for generating hash digests by using the given algorithm. The optional options are used for controlling the stream behaviour. For some hash functions like XOF and 'shake256' the output length is used for specifying the desired output length in bytes.Syntaxcrypto.createHash(algorithm, [options])ParametersThe above parameters are described as below −algorithm – This algorithm is used for generating the hash digests. Input type is string.options – These are optional parameters which can be used for controlling the stream behaviour.ExampleCreate a file with name – createHash.js and copy ... Read More

crypto.createDiffieHellman(primeLength, [generator]) Method in Node.js

Mayank Agarwal
Updated on 20-May-2021 11:51:20

58 Views

The crypto.createDiffieHellmanGroup(primeLength, [generator]) method is used for creating a key exchange object that generates a prime number of primeLength bits using a numeric generator. Default value is 2 when the generator is not defined.Syntaxcrypto.createDiffieHelmmanGroup(primeLength, [generator])ParametersThe above parameters are described as below −primeLength – The number of prime bits that will be generated. Input value is of type number.generator – Generator for generating the exchange key object. Default value: 2.ExampleCreate a file with name – index.js and copy the below code snippet. After creating file, use the following command to run this code as shown in the example below −node index.jsindex.js Live Demo// crypto.createDiffieHellman(primeLength, ... Read More

crypto.createDiffieHellman() Method in Node.js

Mayank Agarwal
Updated on 20-May-2021 11:50:54

221 Views

The above method creates a DiffieHellman key exchange object with the help of the supplied prime value and an optional specific generator. The generator argument can hold either a string, number or Buffer value. Default value for generator is 2.Syntaxcrypto.createDiffieHelmmanGroup(prime, [primeEncoding], [generator], [generatorEncoding]ParametersThe above parameters are described as below −prime – The number of prime bits that will be generated. Input value is of type number.primeEncoding – This parameter defines the encoding of the prime string. Possible input types are: string, buffer, TypedArray and DataView.generator – Generator for generating the exchange key object. Default value: 2.generatorEncoding – This parameter defines the generator string encoding.ExampleCreate ... Read More

Advertisements