Found 254 Articles for Node.js

Node.js – Timers Module – Scheduling Timers

Mayank Agarwal
Updated on 27-Oct-2021 07:51:47

348 Views

The timers module contains functions that can execute code after a certain period of time. You do not need to import the timer module explicitly, as it is already globally available across the emulated browser JavaScript API.Timers module is mainly categorised into two categoriesScheduling Timers − This timer schedules the task to take place after a certain instant of time.setImmediate()setInterval()setTimeout()Cancelling Timers − This type of timers cancels the scheduled tasks which is set to take place.   ClearImmediate()clearInterval()clearTimeout()Scheduling Timers1. setTimeout() MethodThe setTimeout() method schedules the code execution after a designated number of milliseconds. Only after the timeout has occurred, the code ... Read More

Data Chunks in Node.js

Mayank Agarwal
Updated on 18-Aug-2021 09:52:53

3K+ Views

Data chunks in Node.js or any other language can be defined as a fragment of data that is sent to all the servers by the client. The servers make a stream of these chunks and form a buffer stream. This buffer stream is then converted into meaningful data.Syntaxrequest.on('eventName', [callback] )ParametersThe parameters are described below −eventName − It is the name of the event that will be fired.callback − Callback function to handle any error if it occurs.ExampleCreate a file with the name "index.js" and copy the following code snippet. After creating the file, use the command "node index.js" to run ... Read More

Giving Input to a Node.js Application

Mayank Agarwal
Updated on 18-Aug-2021 09:44:44

596 Views

The main aim of a Node.js application is to work as a backend technology and serve requests and return response. But we can also pass inputs directly to a Node.js application.We can use readline-sync, a third-party module to accept user inputs in a synchronous manner.Syntaxnpm install readline-syncThis will install the readline-sync module dependency in your local npm project.Example 1Create a file with the name "input.js" and copy the following code snippet. After creating the file, use the command "node input.js" to run this code.//Giving Input to a Node.js application Demo Example // Importing the realine-sync module const readline = ... Read More

Node.js – util.debuglog() Method

Mayank Agarwal
Updated on 18-Aug-2021 09:42:41

165 Views

The util.debuglog() method creates a function that can be used to write the desired error/debug messages to stderr. These error messages are written only upon the existence of the NODE_DEBUG environment variable.Syntaxutil.debuglog(section, [callback])ParametersThe parameters are described below −section − This parameter takes the portion of the application for which the debug log is being created.callback − This is the callback function which will receive the pointer if any error occurs during the execution of method.Example 1Create a file with the name "debuglog.js" and copy the following code snippet - Live Demo// util.debuglog() demo example // Importing the util module const ... Read More

Node.js – hash.update() Method

Mayank Agarwal
Updated on 18-Aug-2021 09:28:14

424 Views

The Hash class is one of the many utility classes that is used for creating the hash digests of data. The hash.update() method updates the hash content with the data passed, and the encoding that is passed along with the parameters. If the encoding is not passed and the data is a string, ‘utf8’ encoding is used.Syntaxhash.update(data, [inputEncoding])ParametersThe parameters are described below −data − This input parameter takes input for the data that will update the hash content.InputEncoding − Encoding to encode the input data or the data stringExample 1Create a file with the name "hashUpdate.js" and copy the following ... Read More

Node.js – util.types.isNativeError() Method

Mayank Agarwal
Updated on 18-Aug-2021 09:03:01

85 Views

The util.types.isNativeError() method checks whether the passed value is a built-in error type or not. If the above condition is satisfied, it returns True, else False. The error can be of any type.Syntaxutil.types.isNativeError(value)ParametersIt takes a single parameter −value − This input value takes input for the required parameter and checks if it's an error type or not.It returns True or False based upon the input value passed.Example 1Create a file with the name "isNativeError.js" and copy the following code snippet. After creating the file, use the command "node isNativeError.js" to run this code.// util.types.isNativeError() Demo Example // Importing the ... Read More

Node.js – hash.digest() Method

Mayank Agarwal
Updated on 18-Aug-2021 09:26:54

1K+ Views

The Hash class is one of the many utility classes that is used for creating the hash digests of data. The hash.digest() method calculates all the data that needs to be hashed passed inside the hash function and returns them. If an encoding is defined, a string will be returned, else a buffer is returned.Syntaxhash.digest([encoding])ParametersIt takes a single parameter −encoding − This input parameter takes input for the encoding to be applied while calculating the hash.Example 1Create a file with the name "hashDigest.js" and copy the following code snippet. After creating the file, use the command "node hashDigest.js" to run ... Read More

Node.js – util.types.isInt8Array() Method

Mayank Agarwal
Updated on 18-Aug-2021 08:57:53

41 Views

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

Node.js – util.types.isAnyArrayBuffer() Method

Mayank Agarwal
Updated on 18-Aug-2021 08:54:57

49 Views

The util.types.isAnyArrayBuffer() checks whether the passed value is an ArrayBuffer or a SharedArrayBuffer instance. It returns True if the above condition holds, else False.Syntaxutil.types.isAnyArrayBuffer(value)ParametersIt takes a single parameter −value − This input parameter takes input for the required datatype and checks if it's an ArrayBuffer or SharedArrayBuffer instance.It returns True or False based upon the input value passed.Example 1Create a file with the name "isArrayBuffer.js" and copy the following code snippet. After creating the file, use the command "node isArrayBuffer.js" to run this code// util.types.isAnyArrayBuffer() Demo Example // Importing the util module const util = require('util'); // Printing ... Read More

Node.js – util.types.isFloat32Array() Method

Mayank Agarwal
Updated on 18-Aug-2021 08:51:07

39 Views

The util.types.isFloat32Array() method checks whether the passed value is a builtin Float32Array instance or not. If the above condition is satisfied, it returns True, else False.Syntaxutil.types.isFloat32Array(value)ParametersIt takes a single parameter −value − This input value takes input for the required parameter and checks if it's a Float32-Array instance or not.It returns True or False based upon the input value passed.Example 1Create a file with the name – "isFloat32Array.js" and copy the following code snippet. After creating the file, use the command "node isFloat32Array.js" to run this code.// util.types.isFloat32Array() Demo Example // Importing the util module const util = require('util'); ... Read More

Previous 1 ... 7 8 9 10 11 ... 26 Next
Advertisements