Node.js Articles

Page 2 of 22

process.env() Method in Node.js

Mayank Agarwal
Mayank Agarwal
Updated on 11-Mar-2026 537 Views

The process.argv() method is used for getting the user environment object. This object will contain all the information about the environment on which this command is being executed.Syntaxprocess.env()ParametersSince it returns an object for the user environment. It does not need any inputs from the user as such.ExampleCreate a file with name – env.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 env.jsenv.js// Node.js program to demonstrate the use of process.env // Importing the process module const process = require('process'); // Printing the ...

Read More

agent.createConnection() Method in Node.js

Mayank Agarwal
Mayank Agarwal
Updated on 11-Mar-2026 847 Views

The agent.createConnection() method is an interface provided by the 'http' module. This method produces a socket/stream that can be used for the HTTP requests. One can use custom agents to override this method for greater flexibility. A socket/stream can be returned in two ways – either by returning the socket/stream directly from this function, or by passing this socket/stream to the callback.Syntaxagent.createConnection(options, [callback])ParametersThe above function can accept the following parameters −options – These options will contain the connection details for which stream has to be created.callback – This will receive the created socket connection from the agent.ExampleCreate a file with the name ...

Read More

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

Mayank Agarwal
Mayank Agarwal
Updated on 11-Mar-2026 130 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// crypto.createDiffieHellman(primeLength, [generator]) ...

Read More

Creating an Agent in Node.js

Mayank Agarwal
Mayank Agarwal
Updated on 11-Mar-2026 1K+ 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

crypto.createHash() Method in Node.js

Mayank Agarwal
Mayank Agarwal
Updated on 11-Mar-2026 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.createHmac() Method in Node.js

Mayank Agarwal
Mayank Agarwal
Updated on 11-Mar-2026 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.randomBytes() Method in Node.js

Mayank Agarwal
Mayank Agarwal
Updated on 11-Mar-2026 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.pbkdf2() Method in Node.js

Mayank Agarwal
Mayank Agarwal
Updated on 11-Mar-2026 2K+ 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.createECDH() Method in Node.js

Mayank Agarwal
Mayank Agarwal
Updated on 11-Mar-2026 523 Views

The crypto.createECDH() is used to create an elliptic curve also known as Elliptic Curve Diffie-Hellman i.e ECDH that uses a curve predefined by the input parameter curveName. You can use crypto.getCurves to get the list of all the available curve names. This method is part of the 'crypto' module.Syntaxcrypto.createECDH(curveName)ParametersThe above parameters are described as belowcurveName – It takes the input for the curve name. This curveName will deined the predefined curve for creating ECDH.ExampleCreate a file with name – createECDH.js and copy the below code snippet. After creating file, use the following command to run this code as shown in the ...

Read More

crypto.createCipheriv() Method in Node.js

Mayank Agarwal
Mayank Agarwal
Updated on 11-Mar-2026 5K+ Views

The crypto.createCipheriv() method will first create and then return the cipher object as per the algorithm passed for the given key and authorization factor (iv).Syntaxcrypto.createCipheriv(algorithm, key, iv, options)ParametersThe above parameters are described as below −algorithm – It takes the input for the algorithm that would be used to create the cipher. Some possible values are: aes192, aes256, etc.key – It takes input for the raw key that is used by the algorithm and iv. Possible values can be of type: string, buffer, TypedArray or DataView. It can optionally be a type object of secret type.iv – Also known as the initialization vector. This ...

Read More
Showing 11–20 of 212 articles
« Prev 1 2 3 4 5 22 Next »
Advertisements