Found 285 Articles for Node.js

Node.js – dns.getServers() Method

Mayank Agarwal
Updated on 29-Oct-2021 08:28:30

98 Views

The dns.getServers() method returns an array of IP address strings. The address will be formatted as per the RFC 5952 standard, that are configured for DNS resolution. The string will also include the port section if a custom port is used.Syntaxdns.getServers()ParametersSince it returns the list of the servers, it does not need any parameters.Example 1Create a file "getServers.js" and copy the following code snippet. After creating the file, use the command "node getServers.js" to run this code.// dns.getServers() Node js Example // Importing the dns module const dns = require('dns'); // Reading the IP related info // for ... Read More

Node.js – diffieHellman.getPrime() Method

Mayank Agarwal
Updated on 29-Oct-2021 08:26:06

58 Views

diffieHellman.getPrime() returns the Diffie-Hellman generated prime with the specified encoding. It returns a string in case the encoding is passed, else a buffer will be returned.SyntaxdiffieHellman.getPrime([encoding])ParametersIt takes only one parameterencoding – This parameter specifies the encoding of the return value.Example 1Create a file with the name "prime.js" and copy the following code snippet. After creating the file, use the command "node prime.js" to run this code.// diffieHellman.getPrime() Demo Example // Importing cryptoDiffieHellman from the crypto module const { createDiffieHellman } = require('crypto'); // Initializing the diffieHellman const dh = createDiffieHellman(512); // Generating prime from diffieHellman let dhPrime ... Read More

Node.js – dnsPromises.resolveTxt() Method

Mayank Agarwal
Updated on 29-Oct-2021 08:23:22

86 Views

The dnsPromises.resolveTxt() method uses the DNS protocol to resolve the text search (TXT records) for the hostname. The promise is resolved with a twodimensional array of the text records available for the hostname on success.SyntaxdnsPromises.resolveTxt(hostname)ParametersIt takes only one parameterhostname – This parameter takes input for the hostname to be resolved.Example 1Create a file with the name "resolveTxt.js" and copy the following code snippet. After creating the file, use the command "node resolveTxt.js" to run this code.// dns.resolveTxt() Demo Example // Importing the dns module const dns = require('dns'); const dnsPromises = dns.promises; // Passing IP to find the ... Read More

Node.js – dnsPromises.lookup() Method

Mayank Agarwal
Updated on 29-Oct-2021 08:20:54

54 Views

The dnsPromises.lookup() method resolves the hostname (e.g., tutorialspoint.com) into the first found A IPv4) or AAAA (IPv6) record. The properties available under the options are optional.dns.lookup() does not have anything to do with the DNS protocol. The implementation uses an OS facility that can associate names with addresses and vice versa.The difference between the dnsPromises and dns module is that dns.promises provides an alternative way to asynchronous DNS methods that return Promise objects instead of callbacks.SyntaxdnsPromises.lookup(hostname, [options])Parametershostname – This is the website hostname for which you want to look up the DNS values.options – It can have the following optionsfamily ... Read More

Node.js – process.emitWarning() Method

Mayank Agarwal
Updated on 29-Oct-2021 08:13:50

163 Views

The process.emitWarning() method can be used to emit custom or user-defined process warnings. This can be listened by adding a handler to the warning event.Syntaxprocess.emitWarning(warning, [options])Parameterswarning – This is the warning that will be emitted.options –type – This is the type of warning being emitted. Default ‘Warning’code – This is a unique identifier for the warning that will be emitted.ctor – This is an optional function used to limit the generated stack trace.detail – This is the additional text to be included with the error.Example 1Create a file with the name "warning.js" and copy the following code snippet. After creating ... Read More

Node.js – dns.resolveTxt() Method

Mayank Agarwal
Updated on 29-Oct-2021 08:07:24

256 Views

The dns.resolveTxt() method uses the DNS protocol to resolve the text queries (TXT Records) for the hostname. The addresses argument passed to the callback function is a two-dimensional array that contains the array of text records available for the hostname.Syntaxdns.resolveTxt(hostname, callback)Parametershostname – This parameter takes input for hostname to be resolvedcallback – This function will catch errors, if any.records – Returns TXT records for the hostname.Example 1Create a file with the name "resolveTxt.js" and copy the below code snippet. After creating file use the command "node resolveTxt.js" to run this code.// dns.resolveTxt() Demo Example // Importing the dns module ... Read More

Node.js – process.report Property

Mayank Agarwal
Updated on 29-Oct-2021 07:58:52

142 Views

process.report is an object whose methods generate the diagnostic reports for the current process. It is found under the process module.Syntaxprocess.reportExample 1Create a file with the name "report.js" and copy the following code snippet. After creating the file, use the command "node report.js" to run this code.// process.report Demo Example // Importing the process module const process = require('process'); // Getting reports for the below processes const reports = process.report; // Printing out the result console.log(reports)OutputuC:\homeode>> node report.js {    writeReport: [Function: writeReport],    getReport: [Function: getReport],    directory: [Getter/Setter],    filename: [Getter/Setter],    compact: [Getter/Setter],   ... Read More

Node.js – dns.lookup() Method

Mayank Agarwal
Updated on 29-Oct-2021 07:31:40

533 Views

The dns.lookup() method resolves the host name (e.g., tutorialspoint.com) into the first found A IPv4) or AAAA (IPv6) record. The properties available under the options are optional. dns.lookup() does not have anything to do with the DNS protocol. The implementation uses an OS facility that can associate names with addresses and vice versa.Syntaxdns.lookup(hostname, [options], callback)ParametersThe above parameters are defined as below −hostname – This is the website hostname for which you want to look up the DNS values.options – It can have the following optionsfamily – It can have the values 4, 6, or 0 only. The value "0" indicates ... Read More

Node.js – dns.resolveNs() Method

Mayank Agarwal
Updated on 29-Oct-2021 07:27:42

37 Views

The dns.resolveNs() method uses the DNS protocol to resolve the nameserver records (NS Records) for the hostname. The addresses argument passed to the callback function will contain an array of nameserver records for the hostname.Syntaxdns.resolveNs(hostname, callback)ParametersThe above parameters are defined as below −hostname – This parameter takes input for the hostname to be resolved.callback – This function will catch errors, if any.records – Returns the nameserver (NS) records for the hostname.Example 1Create a file "resolveNs.js" and copy the following code snippet. After creating the file, use the command "node resolveNs.js" to run this code:// dns.resolveNs() Demo Example // Importing ... Read More

Node.js – process.connected Property

Mayank Agarwal
Updated on 29-Oct-2021 07:24:49

41 Views

The process.connected property returns True if an IPC channel is connected and will return False after the process.disconnect() method is called. This happens only when the node process is spawned with an IPC channel (i.e., Child process and Cluster).Once the process.connected property is false, no messages can be sent over the IPC channel.Syntaxprocess.connectedExample 1Create two files "parent.js" and "child.js" as follows −parent.js// process.connected Property Demo Example // Importing the child_process modules const fork = require('child_process').fork; // Attaching the child process file const child_file = 'util.js'; // Spawning/calling child process const child = fork(child_file);child.jsconsole.log('In Child') // Check ... Read More

Previous 1 ... 6 7 8 9 10 ... 29 Next
Advertisements