Found 266 Articles for Node.js

Node.js – dnsPromises.resolveAny() Method

Mayank Agarwal
Updated on 24-Nov-2021 06:38:52

193 Views

The dnsPromises.resolveAny() method uses the DNS protocol to resolve all records (this is also known as ANY or * query). The promise is resolved with an array containing various types of records.TypeProperties'A'IPv4 address'AAAA'IPv6 address'Any'Any RecordsMXMail Exchange RecordsNAPTRName authority pointer recordsNSName server recordsPTRPointer RecordsSOAStart of Authority RecordsSRVService RecordsTXTText RecordsCNAMECanonical Name RecordsSyntaxdnsPromises.resolveAny(hostname)Parametershostname - This parameter takes input for the hostname to be resolved.Example 1Create a file with the name "resolveAny.js" and copy the following code. After creating the file, use the command "node resolveAny.js" to run this code, as shown in the example below −// Node.js program to demonstrate the // dnsPromises.resolveAny() method ... Read More

Node.js – process.throwDeprecation() Method

Mayank Agarwal
Updated on 24-Nov-2021 06:26:36

77 Views

This method indicates about the flag value of --throw-deprecation which is set to True or False on the current Node.js project.The process.throwDeprecation() method is mutable, so the deprecation warning results in errors may be altered at runtime.Syntaxprocess.throwDeprecation( )Example 1Create a file with the name "throwDeprecation.js" and copy the following code. After creating the file, use the command "node throwDeprecation.js" to run this code as shown in the example below// process.throwDeprecation() Demo Example // Importing the process module const process = require('process'); // Printing the --throw-Deprecation default value console.log(process.throwDeprecation);Output 1undefinedOutput 2trueExample 2Let's take another example// process.throwDeprecation() Demo Example ... Read More

Node.js – dns.resolve4() Method

Mayank Agarwal
Updated on 24-Nov-2021 05:32:49

217 Views

The dns.resolve4() method uses the DNS protocol to resolve a IPv4 address for the hostname. The arguments passed to the callback function can contain an array of multiple addresses.Syntaxdns.resolve4(hostname, [options], callback)Parametershostname - This parameter takes input for the hostname to be resolved.options - It can have the following optionsttl - It defines the Time-To-Live (TTL) for each record. Callback receives an array of addresses like this{ address: '1.2.3.4', ttl:60 }callback - It will catch errors, if any.Example 1Create a file with the name "resolve4.js" and copy the following code snippet. After creating the file, use the command "node resolve4.js" to ... Read More

Node.js – Immediate Timer Class

Mayank Agarwal
Updated on 29-Oct-2021 08:59:59

220 Views

The Immediate Timer class is used for scheduling the functions that we need to call at a certain period of time in future. These tasks can be scheduled by using the Immediate timer class and using the setImmediate() method. The Immediate class has an object for setImmediate() method and it passes the same object to clearImmediate() in case it wants to cancel the scheduled timer function.Given below are the Immediate class ref objects −1. immediate.ref()This method is called if the immediate object is active for too long and did not exit.Syntaximmediate.ref()2. immediate.unref()This object keeps the event loop ‘active’ until False ... Read More

Node.js – diffieHellman.getPublicKey() Method

Mayank Agarwal
Updated on 29-Oct-2021 08:57:58

279 Views

The diffieHellman.getPublicKey() returns the Diffie-Hellman generated public key that is specified by the encoding passed. It will return a string in case the encoding is passed, else it will return a buffer.SyntaxdiffieHellman.getPublicKey([encoding])Parametersencoding – This parameter specifies the encoding of the return value.Example 1Create a file with the name "publicKey.js" and copy the following code snippet. After creating the file, use the command "node publicKey.js" to run this code.// diffieHellman.getPublicKey() Demo Example // Importing the crypto module const crypto = require('crypto') // Initializing the diffieHellman const dh = crypto.createDiffieHellman(512); // Taking default publicKey as null let publicKey = ... Read More

Node.js – Timeout-hasRef() & Timeout-refresh() methods

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

1K+ Views

The Timeout object is internally created and is returned from the setTimeout() and setInterval() method. You can use this object and pass it to either clearTimeout() or clearInterval() methods in order to cancel the scheduled actionsFollowing are the timeout class ref objects that can be used to control the default behaviour1. timeout.hasRef()This method keeps the node event loop active as long as its value is True.Syntaxtimeout.hasRef()2. timeout.refresh()This method refreshes the timer’s start time to the current time and reschedules the timer to its callback where the previously specified duration will be adjusted to the current time. This method helps in ... Read More

Node.js – process.channel Property

Mayank Agarwal
Updated on 29-Oct-2021 08:51:11

220 Views

When a node process is spawned with an IPC channel, the process.channel property provides the reference to that IPC channel. If no IPC channel exists, this property is then undefined.Syntaxprocess.channelExample 1Create two files "channel.js" and "util.js" and copy the following code snippets. After creating the files, use the commands "node channels.js" and "node util.js" to run the codes.channel.js// process.channel Property Demo Example // Importing the process modules const cp = require('child_process'); // Getting reference to the child const process = cp.fork(`${__dirname}/util.js`); // Sending the below message to child process.send({ msg: 'Welcome to Tutorials Point' }); console.log(process.channel)util.js// ... Read More

Node.js – dnsPromises.resolve4() Method

Mayank Agarwal
Updated on 29-Oct-2021 08:48:15

366 Views

The dnsPromises.resolve4() method uses the DNS protocol to resolve IPv4 addresses (A records) for the hostname. A promise is resolved with an array of IP addresses when True.The difference between the dnsPromises and dns module is that dnsPromises provides an alternative way to asynchronous DNS methods that return Promise objects instead of callbacks.Syntaxdns.resolve4(hostname, [options])Parametershostname – This parameter takes input for hostname to be resolved.options – It can have the following options −ttl – This defines the Time-To-Live (TTL) for each record. Callback receives an array of addresses like this – { address: ‘1.2.3.4’, ttl:60 }Example 1Create a file "resolve4.js" and ... Read More

Node.js – dns.resolveNaptr() Method

Mayank Agarwal
Updated on 29-Oct-2021 08:45:45

76 Views

The dns.resolveNaptr() method uses the DNS protocol to resolve regular expression based words (NAPTR records) for the hostname. The addresses argument passed to the callback function will contain an array of objects with the following properties −flagsserviceregexpreplacementorderpreferenceSyntaxdns.resolveNaptr(hostname, callback)Parametershostname – This parameter takes input for the hostname to be resolved.callback – This function will catch errors, if any.Records – Returns NAPTR records for the hostname.Example 1Create a file "resolveNaptr.js" and copy the following code snippet. After creating the file, use the command "node resolveNaptr.js" to run this code.// dns.resolveNaptr() Demo Example // Importing the dns module const dns = require('dns'); ... Read More

Node.js – dnsPromises.lookupService() Method

Mayank Agarwal
Updated on 29-Oct-2021 08:36:44

107 Views

The dns.lookupService() method resolves the given address and port into a hostname and service. This method uses the operating system’s underlying getnameinfo implementation.A TypeError will be thrown if the address is not a valid IP address. The difference between the dnsPromises and dns module is that dnsPromises provides an alternative way to asynchronous DNS methods that return Promise objects instead of callbacks.SyntaxdnsPromises.lookupService(address, port)Parametersaddress – This parameter takes input for the IP address that needs to be resolved.port – This parameter takes input for the port number that is attached with the IP address.Example 1Create a file with the name "lookupService.js" ... Read More

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