Found 266 Articles for Node.js

Node.js – hmac.digest() Method

Mayank Agarwal
Updated on 16-Aug-2021 12:10:41

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. Live Demo// Hmac.digest() Demo Example // Importing the crypto module ... Read More

Node.js – hash.copy() Method

Mayank Agarwal
Updated on 16-Aug-2021 12:08:01

303 Views

The Hash class is one of the many utility classes that is used for creating the hash digests of data. The hash.copy() method creates a new Hash object that will contain a deep copy of the internal state of the current hash object.Syntaxhash.copy([options])Parametersoptions −This input parameter takes input to control the stream behaviour and therefore will contain the stream.tranformOptions.Example 1Create a file "hashCopy.js" and copy the following code snippet. After creating the file, use the command "node hashCopy.js" to run this code.// hash.update() demo Example // Importing the crypto module const crypto = require('crypto'); // Defining the hash ... Read More

Node.js – util.inherits() Method

Mayank Agarwal
Updated on 16-Aug-2021 12:04:46

556 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

Node.js – util.inspect() method

Mayank Agarwal
Updated on 16-Aug-2021 12:01:15

1K+ 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

Timing features in Node.js

Mayank Agarwal
Updated on 16-Aug-2021 11:57:15

659 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.types.isInt32Array() Method

Mayank Agarwal
Updated on 16-Aug-2021 11:51:42

128 Views

The util.types.isInt32Array() method checks whether the passed value is a built-in Int32Array instance or not. If the above condition is satisfied, it returns True, else False.Syntaxutil.types.isInt32Array(value)Parametersvalue − This input takes input for the required parameter and checks if it's an Int32Array instance or not. Returns True or False based upon the input value passed.Example 1Create a file with name isInt32Array.js and copy the below code snippet.After creating the file, use the following command to run this code and check the output -node isInt32Array.jsProgram Code// util.types.isInt32Array() Demo Example // Importing the util module const util = require('util'); // Passing normal ... Read More

How to Install Newman using NPM?

Debomita Bhattacharjee
Updated on 25-Jun-2021 13:39:59

2K+ Views

We can install Newman using npm. Newman can be installed using npm and Node.js. To download Node.js, navigate to the link − https://nodejs.org/en/download/current/.As we have downloaded Node.js successfully, we can check it with the below command −In Windowsnode --vIn Linuxnode --versionThe npm package becomes available automatically on installing Node.js. We can check it with the below command −In Windowsnpm --vIn Linuxnpm --versionFinally to install Newman, run the below command −For Windowsnewman --vFor Linuxnewman --version

Stream writable.writableObjectMode Property in Node.js

Mayank Agarwal
Updated on 20-May-2021 13:33:59

219 Views

The writable.writableObjectMode property is used for getting the objectMode property of the given writable Stream. The property will return 'true' if the object mode is set, else 'false' will be returned.Syntaxwriteable.writableObjectModeExampleCreate a file with name – writableObjectMode.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 writableObjectMode.jswritableObjectMode.js Live Demo// Program to demonstrate writable.writableObjectMode property // Importing the stream module const stream = require('stream'); // Setting the objectMode to true objectMode: true // Creating a data stream with writable const writable = new stream.Writable({   ... Read More

Stream writable.writableLength Property in Node.js

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

236 Views

The writable.writableLength property is used for displaying the number of bytes or objects which are there in the queue that are ready to be written. This is used for inspecting the data as per the status from highWaterMark.Syntaxwriteable.writableLengthExample 1Create a file with name – writableLength.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 writableLength.js Live Demo// Program to demonstrate writable.writableLength method const stream = require('stream'); // Creating a data stream with writable const writable = new stream.Writable({    // Writing the data from stream ... Read More

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

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

692 Views

The writable.cork() method is used for forcing all the written data to be buffered inside a memory. This buffered data will only be removed from the buffer memory after stream.uncork() or stream.end() method have been called.Syntaxcork()writeable.cork()uncork()writeable.uncork()ParametersSince it buffers the written data. Only parameter that's needed will be the writable data.ExampleCreate a file with name – cork.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 cork.jscork.js Live Demo// Program to demonstrate writable.cork() method const stream = require('stream'); // Creating a data stream with writable const ... Read More

Advertisements