Found 10483 Articles for Web Development

agent.maxFreeSockets Property in Node.js

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

486 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

4K+ 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

1K+ 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

3K+ 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

3K+ 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

96 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

347 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

assert.deepStrictEqual() function in Node.js

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

261 Views

The assert module provides a bunch of different functionalities that are used for function assertion. One of them is deepStrictEqual() function. This function is used to test the deep equality between the actual and expected parameters. An assertion error will be raised if the condition is not fulfilled.Syntaxassert.deepStrictEqual(actual, expected[, message])ParametersThe above parameters are described as below −actual – This is the actual value that will be evaluated against the expected parameters.expected – This is the expected parameter value which is matched against the actual value.message – This parameter holds the string message value to be printed if the actual and expected parameters do ... Read More

Logging in Node.js

Mayank Agarwal
Updated on 20-May-2021 11:24:21

401 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 carefully configured ... Read More

Advertisements