Articles on Trending Technologies

Technical articles with clear explanations and examples

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

Mayank Agarwal
Mayank Agarwal
Updated on 29-Oct-2021 2K+ 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

What is Operator Precedence Parsing?

Ginni
Ginni
Updated on 29-Oct-2021 15K+ Views

Operator Precedence Parsing is also a type of Bottom-Up Parsing that can be used to a class of Grammars known as Operator Grammar.A Grammar G is Operator Grammar if it has the following properties −Production should not contain ϵ on its right side.There should not be two adjacent non-terminals at the right side of production.Example1 − Verify whether the following Grammar is operator Grammar or not.E → E A E |(E)|idA → +| − | ∗SolutionNo, it is not an operator Grammar as it does not satisfy property 2 of operator Grammar.As it contains two adjacent Non-terminals on R.H.S of ...

Read More

Node.js – process.channel Property

Mayank Agarwal
Mayank Agarwal
Updated on 29-Oct-2021 253 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
Mayank Agarwal
Updated on 29-Oct-2021 421 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
Mayank Agarwal
Updated on 29-Oct-2021 102 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
Mayank Agarwal
Updated on 29-Oct-2021 134 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

Node.js – process ‘exit’ Event

Mayank Agarwal
Mayank Agarwal
Updated on 29-Oct-2021 825 Views

An ‘exit’ event is emitted when the process is going to exit due to the following reasons −Process.exit() method is called explicitly.The node event loop no longer have any task to perform.SyntaxEvent: 'exit'Example 1Create a file "exit.js" and copy the following code snippet. After creating the file, use the command "node exit.js" to run this code.// Process 'Exit' event Demo Example console.log("Process Starts") // Binding this event to the handler process.on('exit', () => {    console.log("process.exit() method is called") }) console.log("Process Ends") // Exiting the process process.exit()OutputProcess Starts Process Ends process.exit() method is calledExample 2Let’s take a ...

Read More

Construct NFA for the following language and convert it into DFA using the algorithm - L = (aa+ (bb*)c*)

Ginni
Ginni
Updated on 29-Oct-2021 1K+ Views

SolutionNFA for the above language will be −Conversion from NFA to DFA −ε − closure(0) = {0, 1, 4} = AFor State AFor input symbol aFor input symbol bFor input symbol c∴ Ta = {2}∴ Tb = {5}Tc = ∅∴ ε − closure (Ta)                       = ε                      − closure (2)= {2} = B∴ ε − closure (Tb)                        = ε                        ...

Read More

Node.js – dns.getServers() Method

Mayank Agarwal
Mayank Agarwal
Updated on 29-Oct-2021 201 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
Mayank Agarwal
Updated on 29-Oct-2021 149 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
Showing 37761–37770 of 61,248 articles
Advertisements