Found 6683 Articles for Javascript

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

67 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

244 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

189 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

315 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

Integrating Express-rate-limit in Node.js

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

305 Views

Rate-limiting is becoming important day by day to prevent websites from DOS & DDOS attacks. The rate-limiting prevents the system from any type of fake requests or other brute force attacks. Rate limiting limits the number of times an IP can make requests. The expressrate-limit is the npm package to limit the number of requests from a user.Installing the rate-limit moduleRun the below command to install the express rate-limiting module in your application.npm install --save express-rate-limitExampleCreate a file with name – rateLimit.js and copy the below code snippet. After creating file, use the following command to run this code as ... Read More

Creating custom modules in Node.js

Mayank Agarwal
Updated on 20-May-2021 11:22:48

2K+ Views

The node.js modules are a kind of package that contains certain functions or methods to be used by those who imports them. Some modules are present on the web to be used by developers such as fs, fs-extra, crypto, stream, etc. You can also make a package of your own and use it in your code.Syntaxexports.function_name = function(arg1, arg2, ....argN) {    // Put your function body here... };Example - Custom Node ModuleCreate two file with name – calc.js and index.js and copy the below code snippet.The calc.js is the custom node module which will hold the node functions.The index.js ... Read More

Creating an Agent in Node.js

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

845 Views

You can use new Agent() method to create an instance of an agent in Node. The http.request() method uses the globalAgent from the 'http' module to create a custom http.Agent instance.Syntaxnew Agent({options})ParametersThe above function can accept the following Parameters −options – These options will contain the configurable options that could be set on an Agent while creation. Below are the fields/options the Agent can have −keepAlive – This method keeps the sockets around whether there are any outstanding requests or not, but keeps them for any future requests without actually re-establishing the TCP connection. One can use 'close' connection' to close this connection. ... Read More

Advertisements