Javascript Articles

Page 176 of 534

crypto.getHashes() Method in Node.js

Mayank Agarwal
Mayank Agarwal
Updated on 15-Mar-2026 295 Views

The crypto.getHashes() method returns an array containing the names of all supported hash algorithms available in Node.js. This is useful for discovering what hashing options are available in your current Node.js environment. Syntax crypto.getHashes() Parameters This method takes no parameters and returns an array of supported hash algorithm names. Return Value Returns an array of strings, where each string is the name of a supported hash algorithm. Example // Importing the crypto module const crypto = require('crypto'); // Get all supported hash algorithms const hashAlgorithms = crypto.getHashes(); ...

Read More

crypto.privateDecrypt() Method in Node.js

Mayank Agarwal
Mayank Agarwal
Updated on 15-Mar-2026 2K+ Views

The crypto.privateDecrypt() method is used for decrypting data that was previously encrypted using the corresponding public key with crypto.publicEncrypt(). This method is essential for implementing asymmetric encryption in Node.js applications. Syntax crypto.privateDecrypt(privateKey, buffer) Parameters The method accepts the following parameters: privateKey – Can be an Object, String, Buffer, or KeyObject containing: oaepHash – Hash function for OAEP padding and MGF1. Default: 'sha1' oaepLabel – Label for OAEP padding. ...

Read More

crypto.randomFill() Method in Node.js

Mayank Agarwal
Mayank Agarwal
Updated on 15-Mar-2026 307 Views

The crypto.randomFill() method in Node.js fills an existing buffer with cryptographically strong random data. Unlike crypto.randomBytes() which creates a new buffer, randomFill() fills a provided buffer with random data. Syntax crypto.randomFill(buffer, [offset], [size], [callback]) Parameters buffer – The buffer to be filled. Supported types: Buffer, TypedArray, ArrayBuffer, DataView. Maximum size is 2**31-1. offset – Starting position for filling (optional). Default is 0. size – Number of bytes to fill from the offset (optional). Default is buffer.length - offset. callback – Function called when operation completes or errors occur (optional). Example: Basic ...

Read More

crypto.randomFillSync() Method in Node.js

Mayank Agarwal
Mayank Agarwal
Updated on 15-Mar-2026 512 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. Syntax crypto.randomFillSync(buffer, [offset], [size]) Parameters The 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. ...

Read More

crypto.scrypt() Method in Node.js

Mayank Agarwal
Mayank Agarwal
Updated on 15-Mar-2026 877 Views

The crypto.scrypt() method provides an asynchronous implementation of the scrypt password-based key derivation function. Scrypt is designed to be computationally expensive and memory-intensive, making it resistant to brute-force attacks by requiring significant resources to compute. Syntax crypto.scrypt(password, salt, keylen, [options], callback) Parameters The parameters are described below: password – The password to derive a key from. Can be a string, Buffer, TypedArray, or DataView. ...

Read More

Decipher.final() Method in Node.js

Mayank Agarwal
Mayank Agarwal
Updated on 15-Mar-2026 427 Views

The decipher.final() method in Node.js is used to return the remaining decrypted data from a decipher object. It is part of the crypto module's Decipher class and must be called to complete the decryption process. Once called, the decipher object cannot be used to decrypt additional data. Syntax decipher.final([outputEncoding]) Parameters outputEncoding – Optional. The encoding format for the output. Possible values include 'utf8', 'hex', 'base64', etc. If not specified, a Buffer is returned. Return Value Returns a Buffer or string containing the final decrypted data, depending on whether outputEncoding is ...

Read More

decipher.update() Method in Node.js

Mayank Agarwal
Mayank Agarwal
Updated on 15-Mar-2026 454 Views

The decipher.update() method is used to decrypt encrypted data incrementally in Node.js. It processes encrypted data according to specified encoding formats and is part of the Decipher class within the crypto module. Syntax decipher.update(data, [inputEncoding], [outputEncoding]) Parameters data – The encrypted data to be decrypted. Can be a string or Buffer depending on inputEncoding. inputEncoding – (Optional) The encoding of the input data. Common values: 'hex', 'base64'. If omitted, data is treated as a Buffer. outputEncoding – (Optional) The encoding for ...

Read More

process.cpuUsage() Method in Node.js

Mayank Agarwal
Mayank Agarwal
Updated on 15-Mar-2026 1K+ Views

The process.cpuUsage() method returns CPU time consumption information for the current Node.js process. It provides data about user and system CPU time in microseconds (10^-6 seconds). Syntax process.cpuUsage([previousValue]) Parameters previousValue – Optional parameter. A previous return value from calling process.cpuUsage() to calculate the difference in CPU usage. Return Value Returns an object with two properties: user – CPU time spent in user code (microseconds) system – CPU time spent in system calls (microseconds) Example: ...

Read More

process.env() Method in Node.js

Mayank Agarwal
Mayank Agarwal
Updated on 15-Mar-2026 548 Views

The process.env property in Node.js provides access to environment variables. It returns an object containing all environment variables available to the current process, making it essential for configuration management in Node.js applications. Syntax process.env Note: process.env is a property, not a method, so it doesn't require parentheses. Parameters process.env is a read-only object that doesn't accept parameters. It automatically contains all environment variables from the system where the Node.js process is running. Example: Accessing All Environment Variables Create a file named env.js and run it using: node env.js ...

Read More

Reading a text file into an Array in Node.js

Mayank Agarwal
Mayank Agarwal
Updated on 15-Mar-2026 6K+ Views

Reading text files into arrays is a common task in Node.js applications. The built-in fs module provides both synchronous and asynchronous methods to read files and convert their content into arrays by splitting lines. Using fs.readFileSync() (Synchronous) The synchronous approach blocks code execution until the file is completely read. This method is suitable for smaller files or when you need the data immediately. // Importing the fs module const fs = require("fs"); // Function to read file and convert to array const readFileLines = filename => fs.readFileSync(filename) .toString('UTF8') .split(''); ...

Read More
Showing 1751–1760 of 5,340 articles
« Prev 1 174 175 176 177 178 534 Next »
Advertisements