Found 254 Articles for Node.js

Node.js – util.inherits() Method

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

360 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

943 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

523 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

59 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

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

144 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

155 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

474 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

urlObject.auth() Method in Node.js

Mayank Agarwal
Updated on 20-May-2021 13:29:12

75 Views

The auth() property defines the username and password portion of any URL, also called as userInfo. The string and username are separated by a colon ( : ).SyntaxurlOject.auth()ParametersSince it retuns only the username and password from a URL, it does not required any input parameters.ExampleCreate a file with name – auth.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 auth.jsauth.js Live Demo// Importing the URL module const url = require('url'); var adr = 'https://username=hello:password=tutorialspoint@www.tutorialspoint.com/'; // Parsing the above URL address var q = ... Read More

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

Mayank Agarwal
Updated on 20-May-2021 13:28:45

4K+ Views

The send() and json() functions are used for sending the response to the client directly from the server. The send() method will send the data in a string format, whereas the json() function will send the same in JSON format. The sendStatus() method is used for sending the HTTP request status with the client. Possible status values are: 200(Success), 404(Not found), 201(Created), 503(Server Unreachable) etc.PrerequisiteNode.jsExpress.jsInstallationInstall the express module using the below statement −npm install expressExample - sendStatus()Create a file with name – sendStatus.js and copy the below code snippet. After creating file, use the following command to run this code ... Read More

Advertisements