Node.js DNS Reverse Method

Mayank Agarwal
Updated on 17-Jan-2022 11:53:57

2K+ Views

The dns.reverse() method is somewhat opposite of the method dns.lookup().This method performs a reverse DNS query that resolves an IPv4 or IPv6 to an array of host names.Syntaxdns.reverse(ip, callback)Parametersip – This takes an input for ip as a string, for which the DNS needs to be found.callback – It will catch errors, if any.Example 1Create a file with the name "reverse.js" and copy the following code snippet. After creating the file, use the command "node reverse.js" to run this code as shown in the example below −// dns.reverse() method Demo Example // Importing the dns module const dns = ... Read More

Node.js Client: hgetall and client.hmset in Redis

Mayank Agarwal
Updated on 17-Jan-2022 11:47:52

3K+ Views

Redis commands mostly take the input as a single string or an array of strings as arguments and the replies are sent back as a single string or an array of strings. But, while dealing with the hash values, there are a couple of exceptions.The client.hgetall() function in Node.js – Redis returns an Object keyed by the Hash keys. The strings will be returned either as a string or as a buffer depending upon the setting.The client.hmset() function supplies the Hash arguments to Redis.Syntaxclient.hmset()client.hmset(hash, key1, val1, ...keyN, valN, [callback])client.hgetall()client.hgetall(hash, callback)Example 1Create a file with the name "hmset.js" and copy the ... Read More

Exit a Process in Node.js

Mayank Agarwal
Updated on 17-Jan-2022 11:42:16

11K+ Views

There are some cases where we need to exit a certain process in Node.js based upon a condition. For this condition, we have the following methods where we can escape or exit any Node.js Process.Method 1: Using the Ctrl+C keyI hope everyone knows this shortcut to exit any Node.js process from outside. This shortcut can be used to stop any running process by hitting this command on terminal.Method 2: Using the process.exit() functionThis function instructs Node.js to end the process that is running at an instant with an exit code. Node.js will force the current running process to stop execution ... Read More

Node.js dns.promises.reverse Method

Mayank Agarwal
Updated on 17-Jan-2022 11:35:55

193 Views

The dnsPromises.reverse() method performs a reverse DNS search to resolve the IPv4 or Ipv6 address to an array of hostnames. The promise is rejected with an Error object if a Success status is not encountered.SyntaxdnsPromises.reverse( ip )where, ip is the parameter that takes the input for the IP address to be resolved.Example 1Create a file with the name "reverse.js" and copy the following code snippet. After creating the file, use the command "node reverse.js" to run this code as shown in the example below −// dns.reverse() Demo Example // Importing the dns module const dns = require('dns'); const ... Read More

Node.js DNS resolveSOA Method

Mayank Agarwal
Updated on 17-Jan-2022 11:30:06

100 Views

The dns.resolveSoa() method uses the DNS protocol to resolve the start of authority records for the hostname. The address argument passed to the callback function will be an object that will contain the following properties −nsnamehostmasterserialrefreshentryexpireSyntaxdns.resolveSoa(hostname, callback)ParametersIt accepts the following parameters −hostname – This parameter takes the input for the hostname to be resolved.callback – This function will catch errors, if any.records – Returns the start of authority records for the hostname.ExampleCreate a file with the name "resolveSoa.js" and copy the following code snippet. After creating the file, use the command node "resolveSoa.js" to run this code as shown in ... Read More

Download a File Using Node.js

Mayank Agarwal
Updated on 17-Jan-2022 11:23:34

11K+ Views

We can download file using Node.js by either using third-party libraries or using some inbuilt packages.Method 1: Using 'https' and 'fs' moduleWe can use the http GET method to fetch the files that are to be downloaded.The createWriteStream() method from fs module creates a writable stream and receives the argument with the location of the file where it needs to be saved.pipe() is another method from fs that reads the data from the readable stream and writes it onto the writable stream and file.Example 1Create a file with the name downloadFile.js and copy the following code snippet. After creating the ... Read More

Node.js DiffieHellman computeSecret Method

Mayank Agarwal
Updated on 17-Jan-2022 10:45:35

244 Views

The diffieHellman.computeSecret() is used for computing the shared secret using the public key of other's party and returning the computed shared secret. The suppliedKey is interpreted using the specified inputEncoding and the secret is encoded using the specified outputEncoding. If the inputEncoding is not specified the other publicKey is expected to be a buffer, DataView.SyntaxdiffieHellman.computeSecret(otherPublicKey, [inputEncoding], [outputEncoding])ParametersotherPublicKey – This is the public key that is used to compute the secret.inputEncoding – This encoding is used to interpret the supplied key.outputEncoding – This encoding is used for encoding the computed secret value.Example 1Create a file with the name "computeSecret.js" and copy ... Read More

What Does Thread Count Do in TestNG?

Ashish Anand
Updated on 12-Jan-2022 13:34:13

9K+ Views

TestNG supports multithreading, i.e., a @Test methods can be invoked in parallel. A test or multiple test methods can be invoked from multiple threads. Therefore, multithreading is useful if @Test methods need to be run asynchronously in parallel.Multithreading can be achieved by using the keyword "thread-count=" at Testng.xml. Thread count is basically a number of instances running to execute multiple tests simultaneously or in parallel. The attribute thread-count allows the user to specify how many threads should be run for this execution.In this article, we will illustrate how to achieve multithreading.Approach/Algorithm to solve this problemIn this example, five @Test methods ... Read More

TestNG Annotation Order

Ashish Anand
Updated on 12-Jan-2022 13:31:23

12K+ Views

A TestNG class can have various TestNG methods such as @BeforeTest, @AfterTest, @BeforeSuite, @BeforeClass, @BeforeMethod, @test, etc. In this article, we will explain the order of execution of different TestNG methods.TestNG consists of the following methods to support the main @Test method. The order of execution should be as follows − Key points in this order are:First of all, beforeSuite() method is executed only once.The afterSuite() method executes only once.Even the methods beforeTest(), beforeClass(), afterClass(), and afterTest() methods are executed only once.beforeMethod() method executes for each test case (every time for a new ... Read More

Specify Method Name Sequence in TestNG

Ashish Anand
Updated on 12-Jan-2022 13:21:20

256 Views

A TestNG class can have various TestNG methods such as @BeforeTest, @AfterTest, @BeforeSuite, @BeforeClass, @BeforeMethod, @test, etc. In this article, we will explain the order of execution of different TestNG methods.TestNG consists of the following methods to support the main @Test method. The order of execution should be as follows − Key points in this order are:First of all, beforeSuite() method is executed only once.The afterSuite() method executes only once.Even the methods beforeTest(), beforeClass(), afterClass(), and afterTest() methods are executed only once.beforeMethod() method executes for each test case (every time for a new ... Read More

Advertisements