Node.js Articles

Found 212 articles

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 432 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 802 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

Timing features in Node.js

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

The timer module in Node.js consists of different functions that can control and alter the timings of code execution. In this article, we will see how to use some of these functions.setTimeout() MethodThe setTimeout() method schedules the code execution after a designated amount of milliseconds. Only after the timeout has occurred, the code will be executed. The specified function will be executed only once. This method returns an ID that can be used in clearTimeout() method.SyntaxsetTimeout(function, delay, [args])ParametersThe parameters are defined below:function − This parameter takes input for the function that will be executed.delay − This is the time duration after which ...

Read More

Node.js – util.inspect() method

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

The util.inspect() method returns the string representation of the objects that are intended for the debugging process.Syntaxutil.inspect(object, [showHidden], [depth], [colors])ParametersThe parameters are defined as below:object − A JavaScript primitive type or an object is given as input.optionsshowHidden − This is set as false by default. If true, this option includes the non-enumerable symbols and properties that are included in the formatted result. WeakMap and WeakSet are also included.depth − It specifies the number of recursions to be applied while formatting objects.colors − The output is set styled with ANSI color codes if this value is set to true. Colors passed are customizable.customInspect − The ...

Read More

Node.js – util.inherits() Method

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

The util.inherits() method basically inherits the methods from one construct to another. This prototype will be set to a new object to that from the superConstructor.By doing this, we can mainly add some validations to the top of Object.setPrototypeOf(constructor.prototype, superConstructor.prototype).Syntaxutil.inherits(constructor, superConstructor)ParametersThe parameters are described below -constructor − This is a function type input that holds the prototype for constructor the user wants to be inherited.superConstructor − This is the function that will be used for adding and validating the input validations.Example 1Create a file "inherits.js" and copy the following code snippet. After creating the file, use the command "node inherits.js" to run ...

Read More

Determining the User IP Address in Node

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

Node.js is a completely open source technology that runs on JavaScript runtime environment. When the users want to access a website or link, they connect with the link using their system IP. We can use the dns.lookup() method in Node to find the IP address of the current user.Syntaxdns.lookup(hostname, [options], callback)ParametersThe parameters are described below −hostname − This input parameter consists of the web link which is valid or active.options − Default is 0. It takes input for the IP type, i.e., 4 for Ipv4 and 6 for Ipv6.callback − Handles any error if it occursExample 1Create a file with ...

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