Found 254 Articles for Node.js

Node.js – Retrieving file character encoding

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

848 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

49 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

47 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

133 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

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

Mayank Agarwal
Updated on 17-Aug-2021 12:23:49

46 Views

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

Node.js – Reading Path Parameters from URL

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

2K+ Views

We can embed path variables into the URL and then use these path parameters to retrieve info from resources. These API endpoints have different values with respect to different values passed inside them.Example 1Create a file named "index.js" and copy the following code snippet. After creating the file, use the command "node index.js" to run this code.// Reading Path parameters in Node.js // Importing the below modules const express = require("express") const path = require('path') const app = express() var PORT = process.env.port || 3001 app.get('/p/:tagId', function(req, res) {    console.log("TagId received is : " + req.params.tagId); ... Read More

Node.js – v8.serializer.writeUint32() Method

Mayank Agarwal
Updated on 17-Aug-2021 12:22:18

84 Views

The v8.serializer.writeUint32() method is used for writing a raw 32-bit unsigned integer. This function is mainly used inside the custom serializer._writeHostObject().Syntaxv8.serializer.writeUint32(value)Parametersvalue − This parameter takes input for the 32-bit integer that will be written inside the internal buffer.The function does not return anything, instead it writes the passed value to the internal buffer.Example 1Create a file with the name "writeUint32.js" and copy the following code snippet. After creating the file, use the command "node writeUint32.js" to run this code.// v8.deserialize() Demo Example // Importing the v8 module const v8 = require('v8'); // Initializing the v8 Serializer object const serializer ... Read More

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

Mayank Agarwal
Updated on 17-Aug-2021 12:21:40

53 Views

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

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

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

56 Views

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

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

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

49 Views

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

Advertisements