Programming Articles - Page 1119 of 3363

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

Mayank Agarwal
Updated on 18-Aug-2021 08:31:45

114 Views

The util.types.isArrayBufferView() checks whether the passed value is an instance of the ArrayBuffer views, or typed array objects like DataView. This method returns True if the above conditions are satisfied, else it returns False.Syntaxutil.types.isArrayBufferView(value)ParametersIt takes only one parameter −value − This input parameter takes input for the required datatype and checks if it is an ArrayBuffer or a typed array objectIt returns True or False based upon the input value passed.Example 1Create a file with the name "isArrayBufferView.js" and copy the following code snippet. After creating the file, use the command "node isArrayBufferView.js" to run this code.// util.types.isArrayBufferView() Demo Example ... Read More

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

Mayank Agarwal
Updated on 18-Aug-2021 08:30:17

130 Views

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

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

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

167 Views

The util.types.isAsyncFunction() checks whether the passed value is an async function or not. If the above condition holds, it returns True, else False.Syntaxutil.types.isAsyncFunction(value)ParametersIt takes only one parameter −value − This input value takes input for the required parameter and checks if it is an async function or not.It returns True or False based upon the input value passed.Example 1Create a file with the name "isAsyncFunction.js" and copy the following code snippet. After creating the file, use the command "node isAsyncFunction.js" to run this code.// util.types.isArgumentsObject() Demo Example // Importing the util module const util = require('util'); // Passing ... Read More

Node.js – v8.getHeapStatistics() Method

Mayank Agarwal
Updated on 18-Aug-2021 09:22:25

917 Views

The v8.getHeapStatistics() method returns the statistics about a heap. The getHeapStatistics() method is a part of the v8 module that returns the details about the heap and size of the v8. The getHeapSpaceStatistics() gives stats based upon the spaces in a system, whereas the getHeapStatistics() method gives stats about the whole system.Syntaxv8.getHeapStatistics()ParametersSince it returns the space details/statistics about V8, it does not require any special input parameters. However, the value returned contains the following properties −total_heap_size − This field will return the total heap space size.total_heap_size_executable − This field will return the total heap size that is available for execution.total_physical_size ... Read More

Setting the font color & style of the console in Node.js

Mayank Agarwal
Updated on 18-Aug-2021 09:20:38

920 Views

You can use the chalk module to customize the statements printed on the console.By using it, one can change the text font-color to any color. One can also change the font-style to Bold, Italic or Underlined. Also, you can highlight the printed text.Syntaxnpm install chalkExample 1Create a file "color.js" and copy the following code snippet. After creating the file, use the command "node color.js" to run this code.// Giving color to console statments // Importing the chalk module const chalk = require('chalk'); // Printing the text in blue color console.log(chalk.blue('Welcome to Tutorials Point !')); // Printing the ... Read More

Determining the User IP Address in Node

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

535 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

Node.js – Retrieving file character encoding

Mayank Agarwal
Updated on 17-Aug-2021 12:27:32

1K+ Views

A computer system works upon bits. In the same way, a computer reads files into binary representation which is why we need to convert text characters into binary data. Most popular character encoding types types are: ASCII and Unicode. Unicode has two further types: utf8 and utf16.SyntaxdetectCharacterEncoding(filePath)Setting Up the Environment and Execution:Step I − Initialize the node project.npm initStep II − Install the required modules.npm install detect-character-encodingStep III − Pass the text file name whose encoding is required.Example 1Create a file "abc.txt" with the following text: "Welcome to Tutorials Point" and save it in the project directory.Create a file with the name ... Read More

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

Mayank Agarwal
Updated on 17-Aug-2021 12:26:58

113 Views

The util.types.isGeneratorFunction() method checks whether the passed value is a generator function or not. If the above condition holds, it returns True, else False. The return value may differ from the original source code if a transpilation tool is used.Syntaxutil.types.isGeneratorFunction(value)Parametersvalue − This input value takes input for the required parameter and checks if it's a Generator function or not.It returns True or False based upon the input value passed.Example 1Create a file with the name "isGeneratorFunction.js" and copy the following code snippet. After creating the file, use the command "node isGeneratorFunction.js" to run this code.// util.types.isGeneratorFunction() Demo Example // Importing ... Read More

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

Mayank Agarwal
Updated on 17-Aug-2021 12:25:20

108 Views

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

Node.js – util.formatWithOptions() method

Mayank Agarwal
Updated on 17-Aug-2021 12:24:27

240 Views

The util.formatWithOptions() method works in the same way as the util.format() method. The only difference between the two is that the formatWithOptions() method takes an inspectOptions argument that specifies options that are passed along the util.inspect() method.Syntaxutil.formatWithOptions(inspectOptions, format, [args])ParametersThe parameters are defined below:inspectOptions − These options will be used to inspect the object passed along this method.format − This parameter takes input for the format type of the input value passed.Example 1Create a file with the name "formatWithOptions.js" and copy the following code snippet. After creating the file, use the command "node formatWithOptions.js" to run this code.// Node.js util.formatWithOptions() method ... Read More

Advertisements