Node.js Articles

Page 4 of 22

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 513 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 878 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 428 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 455 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 550 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

script.createCachedData() Method in Node.js

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

The script.createCachedData() method in Node.js creates a code cache for VM scripts, improving performance when executing the same script multiple times. This method is part of the vm module and generates cached bytecode that can be reused. Syntax script.createCachedData() Parameters This method takes no parameters. It creates cached data from the current script instance and returns a Buffer containing the cached bytecode. Return Value Returns a Buffer object containing the cached bytecode that can be used with the cachedData option when creating new script instances. Example 1: Basic Cached Data Creation ...

Read More

Stream writable.cork() and uncork() Method in Node.js

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

The writable.cork() method is used for forcing all written data to be buffered in memory. This buffered data will only be flushed when stream.uncork() or stream.end() methods are called. These methods are useful for optimizing performance by batching multiple write operations. Syntax cork() writable.cork() uncork() writable.uncork() Parameters Both methods take no parameters. The cork() method buffers subsequent write operations, while uncork() flushes the buffered data to the underlying destination. How It Works When cork() is called, all subsequent write operations are buffered in memory instead of being ...

Read More
Showing 31–40 of 212 articles
« Prev 1 2 3 4 5 6 22 Next »
Advertisements