Node.js Articles

Page 5 of 22

Stream writable.writableLength Property in Node.js

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

The writable.writableLength property returns the number of bytes (or objects) in the queue waiting to be written. This property is useful for monitoring buffer status and understanding the backpressure in your writable streams. Syntax writable.writableLength How It Works The property counts data that is: Buffered in the internal queue Waiting to be processed by the _write() method Corked (temporarily held) in memory Data that has already been written or is currently being processed is not counted. Example 1: Basic Usage with Cork Create a file named writableLength.js and run ...

Read More

Stream writable.writableObjectMode Property in Node.js

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

The writable.writableObjectMode property is used to check whether a writable stream is operating in object mode. It returns true if object mode is enabled, false if disabled, or undefined if not explicitly set. Syntax writable.writableObjectMode Return Value Returns a boolean value or undefined: true - Object mode is enabled false - Object mode is explicitly disabled undefined - Object mode not set (default) Example 1: Stream with Object Mode Enabled // Program to demonstrate writable.writableObjectMode property // Importing the stream module const stream = require('stream'); // Creating a ...

Read More

Changing the npm start-script of Node.js

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

The start-script of a Node.js application consists of all the commands that will be used to perform specific tasks. When starting or initializing a Node.js project, there are predefined scripts that will be created for running the application. These scripts can be changed as per the need or demand of the project. Script commands are widely used for making different startup scripts of programs in both Node and React. npm start is used for executing a startup script without typing its execution command. Package.json File Structure The start script needs to be added in the package.json file. ...

Read More

send(), sendStatus() and json() method in Node.js

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

In Express.js, the send(), sendStatus(), and json() methods are essential for sending responses to clients. The send() method sends data in string format, json() sends data in JSON format with proper headers, and sendStatus() sends HTTP status codes with default status messages. Prerequisites Node.js installed Basic understanding of Express.js Installation Install the Express module using npm: npm install express Understanding sendStatus() Method The sendStatus() method sends an HTTP status code along with its default message. Common status codes include 200 (OK), 404 (Not Found), 201 (Created), ...

Read More

SignUp form using Node and MongoDB

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

In this article, we will create a simple user sign-up form using Node.js and MongoDB. When users fill out the form and click submit, their details will be saved to the MongoDB database. Installation Before creating the sign-up form, install the following dependencies: Express - Web framework for Node.js to handle HTTP requests npm install express --save Body-parser - Middleware to parse HTTP POST data npm install body-parser --save Mongoose - MongoDB ...

Read More

Connecting MongoDB with NodeJS

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

To connect MongoDB with Node.js, use the MongoClient.connect() method from the mongodb package. This asynchronous method establishes a connection between your Node.js application and the MongoDB server. Syntax MongoClient.connect(url, options, callback) Parameters: url − Connection string specifying the MongoDB server location and port options − Optional configuration object (e.g., useUnifiedTopology: true) callback − Function executed after connection attempt with error and client parameters Installation and Setup First, install the MongoDB driver for Node.js ? npm install mongodb --save Start your MongoDB server ? mongod --dbpath=data ...

Read More

Node.js – hmac.digest() Method

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

The Hmac class is one of the many utility classes that is used for creating the cryptographic HMAC digests. The Hmac.digest() method is used for calculating all the data that is updated using the Hmac.update() method. If encoding is provided, a string will be returned, else a buffer is returned.Syntaxhmac.digest( [encoding] )Parametersencoding − This input parameter takes input for the encoding to be considered while calculating hmac.Example 1Create a file "hmacDigest.js" and copy the following code snippet. After creating the file use, use the command "node hmacDigest.js" to run this code.// Hmac.digest() Demo Example // Importing the crypto module const ...

Read More

Node.js – util.deprecate() method

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

The util.deprecate() method wraps fn (that may be a function or class) in such a way that it is marketed as a deprecated method. The util.deprecate() method returns a function that emits a DeprecationWarning. This warning is printed to the stderr when the function is called the first time. The function is called without any warning once the warning is emitted.Syntaxutil.deprecate( fn, msg, [code] )ParametersThe parameters are defined below:fn − The function that needs to be deprecated.msg − This is a warning message which is invoked once the deprecated function is called.code − This is an optional parameter which displays the passed ...

Read More

Node.js – hmac.update() Method

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

The Hmac class is one of the many utility classes that is used for creating the cryptographic HMAC digests. The Hmac.update() method is used for updating the Hmac content with the data passed. If encoding is not provided and the data is in string format, then the default encoding 'utf8' is enforced.Syntaxhmac.update(data, [encoding])ParametersThe parameters are described below:data − This input parameter takes input for the data with which Hmac will be updated.encoding − This input parameter takes input for the encoding to be considered while updating the Hmac.Example 1Create a file with the name "hmacUpdate.js" and copy the following code snippet. After ...

Read More

Node.js – forEach() Method

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

The forEach() method in Node.js is used for iterating over a set of given array items. One can iterate over all the values of the array one-by-one using the forEach array loop.SyntaxarrayName.forEach(function)Parametersfunction − The function takes input for the method that will be executed.arrayName − Array that will be iterated.Example 1Create a file "forEach.js" and copy the following code snippet. After creating the file, use the command "node forEach.js" to run this code.// forEach() Demo Example // Defining a vehicle array const vehicleArray = ['bike', 'car', 'bus']; // Iterating over the array and printing vehicleArray.forEach(element => {    console.log(element); });OutputC:\homeode>> ...

Read More
Showing 41–50 of 212 articles
« Prev 1 3 4 5 6 7 22 Next »
Advertisements