process.chdir() Method in Node.js

Mayank Agarwal
Updated on 20-May-2021 13:17:30

5K+ Views

The process.chdir() method is used for changing the current directory of the Node.js process. It will throw an exception if any error occurs or the process fails, but will not return any response on success. For Example: It can fail when the specified directory does not exist.Syntaxprocess.chdir(directory)Parametersdirectory – This will contain the name of the directory that will be updated in place of earlier directory name.ExampleCreate a file with name – chdir.js and copy the below code snippet. After creating file, use the following command to run this code as shown in the example below &Minus;node chdir.jschdir.js Live Demo// Node.js program to ... Read More

process.argv0() Method in Node.js

Mayank Agarwal
Updated on 20-May-2021 13:14:00

157 Views

The process.argv0() method is used for storing the read-only copy of the original value for argv[0] that is passed when the node.js application is started.Syntaxprocess.argv0()ParametersSince it returns only the read-only copy for stored value of argv[0]. It does not need any inputs from the user.ExampleCreate a file with name – argv0.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 argv0.jsargv0.js Live Demo// Node.js program to demonstrate the use of process.argv0 // Importing the process module const process = require('process'); // Printing argv0 value ... Read More

process.argv() Method in Node.js

Mayank Agarwal
Updated on 20-May-2021 13:13:32

4K+ Views

The process.argv() method is used for returning all the command-line arguments that were passed when the Node.js process was being launched. The first element will always contains the same value as process.execPath.Syntaxprocess.argv()ParametersSince it returns all the command line arguments passed before the node.js process. It does not need any inputs from the user.ExampleCreate a file with name – argv.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 argv.jsargv.js Live Demo// Node.js program to demonstrate the use of process.argv // Importing the process module const ... Read More

process.arch() Method in Node.js

Mayank Agarwal
Updated on 20-May-2021 13:12:49

624 Views

The process.arch() method is used for getting the CPU architecture of the computer for which the compilation of current node.js process is taking place. Some of the possible values for the same are: 'arm', 'arm64', 'ia32', 'mips', 'mipsel', 'ppc', 'ppc64', 'x32', 'x64', etc.Syntaxprocess.arch()ParametersSince it returns the architecture for the code where compilation is taking place. It does not need any input. It just returns the architecture name.ExampleCreate a file with name – architecture.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 architecture.jsarchitecture.js Live Demo// Node.js ... Read More

decipher.update() Method in Node.js

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

260 Views

The decipher.update() is used to update the decipher with the receivd data according to the given encoding format. It is one of the inbuilt method that is provided by the class Decipher within the crypto module. If an input encoding is specified, the data argument is a string, else the data argument is a bufferSyntaxdecipher.update(data, [inputEncoding], [outputEncoding])ParametersThe above parameters are described as below −data – It takes the data as an input that is passed to update the decipher content.inputEncoding – It takes the input encoding as a parameter. Possible input values are hex, base64, etc.outputEncoding – It takes the output encoding as ... Read More

Decipher.final() Method in Node.js

Mayank Agarwal
Updated on 20-May-2021 13:04:29

236 Views

The decipher.final() is used to return a buffer or string containing the value of decipher object. It is one of the inbuilt method that is provided by the class Cipher within the crypto module. The decipher method cannot be used to decrypt data once the decipher.final method has been called. Calling the cipher.final method more than once will throw an error.Syntaxdecipher.final([outputEncoding])ParametersThe above parameters are described as below −outputEncoding – It takes the output encoding as a parameter. The input type for this parameter is string. Possible input values are hex, base64, etc.ExampleCreate a file with name – decipherFinal.js and copy the ... Read More

crypto.scrypt() Method in Node.js

Mayank Agarwal
Updated on 20-May-2021 13:04:04

560 Views

The crypto.scrypt() method provides an asynchronous implementation for scrypt method. The scrypt can be defined as a password-based key derivation function that protects the system from the brute-force attacks and makes it unawarding. But the script function is expensive computationally as well as memory-wise.Syntaxcrypto.scrypt(password, salt, keylen, [options], [callback])ParametersThe above parameters are described as below −password – The password field for the scrypt required to decode entry. It can be a string, object, TypedArray, etc.salt – This value should be as unique as possible. This is mainly used for encrypting the data. The minimum suggested length of salt is 16 bytes.keylen – This parameter ... Read More

crypto.randomFillSync() Method in Node.js

Mayank Agarwal
Updated on 20-May-2021 13:03:17

279 Views

The crypto.randomFillSync() method takes a buffer argument and returns the buffer by filling it with its encrypted value. As the name suggests, this will be a sync process.Syntaxcrypto.randomFillSync(buffer, [offset], [size])ParametersThe above parameters are described as below −buffer – This field contains the data content. Possible buffer types are: string, TypedArray, Buffer, ArrayBuffer, DataView. The size of the buffer cannot be greater than 2**31-1.offset – The value of the offset from where randomFill will start. Default value is 0.size – The size of the buffer after the offset, i.e., (buffer.length-offset). This value cannot be greater than 2**31-1.ExampleCreate a file with name – randomFillSync.js and ... Read More

crypto.randomFill() Method in Node.js

Mayank Agarwal
Updated on 20-May-2021 12:57:23

154 Views

Both the crypto.randomFill() method and crypto.randomBytes() method are almost same. The only difference between the two is that – In randomFill() method the first argument is a buffer that will be filled. It also has a callback method that is called when an error is encountered only if the callback is configured.Syntaxcrypto.randomFill(buffer, [offset], [size], [callback])ParametersThe above parameters are described as below −buffer – This field contains the data content. Possible buffer types are: string, TypedArray, Buffer, ArrayBuffer, DataView. The size of the buffer cannot be greater than 2**31-1.offset – The value of the offset from where randomFill will start. Default value is ... Read More

crypto.publicEncrypt() Method in Node.js

Mayank Agarwal
Updated on 20-May-2021 12:54:03

1K+ Views

The crypto.publicEncrypt() is used for encrypting the given data in buffer parameter by using a public key passed in the parameter. The data returned can be decrypted using the corresponding private key.Syntaxcrypto.publicEncrypt(key, buffer)ParametersThe above parameters are described as below −key – It can contain the below 5 types of data of the following type – Object, String, Buffer or KeyObject.key – This field contains the PEM encoded public or private key. It can be of type string, buffer or keyObject.oaepHash – This field contains the hash function to be used for OAEP padding and MGF1. Default value is: 'sha1'.oaepLabel – This field contains the ... Read More

Advertisements