What is the use of DNS module in Node.js?

CWC
2 Min Read

Domain name system is a hierarchical naming system that is used to resolve and look up names in node.js. It is used when you want to access an IP address of a remote server. It consists of asynchronous network wrapper and can be imported via ”var DNS= require (“dns”) command.

How to install

  1. Create a VSCcodeDNSServer. Open it using visual studio code and create a new sub folder and name it script.
  2. Open Node.js and maneuver to the created folder and run npm install-g tsd. Install also tsd query node—action install to enable intellisense of node.js.
  3. Add a file name app.js to the sub folder script and enter the dns=require (�dns’) code in it.

Then load dns module and use it for the following functions:

1. Look up address, options and call back

The dns look up method picks any website address as it first parameter and bring back the corresponding IP4 &IPV6 record. In this case the options parameter can be object or an integer. Where these options miss then the results are valid.

2. Lookup service address, port and callback

This function convert the address and port passed to it as parameters, converts it again into host name then to service name running at the port. It utilizes the getnameinfo process to do the transformations.

3. Dns.resolve addtess, rrbytes, callback

This one changes any physical address to collection of record types. The types are then specified using the second, parameter”rrbyte”.

4. Dns.getServers

This technique bring back a list of all servers that all are currently in use to resolve client requests.

5. Dns.setServers

This is the reverse of the above getservers function. It is used to register all IP address passed to it as resolution servers.

So, from above you first install the dns function then use it up to perform the various look up functions.

[vc_row][vc_column][td_block_21 separator=”” tag_slug=”node-js” limit=”40″ tdc_css=””][/vc_column][/vc_row]

TAGGED:
Share This Article
Leave a comment

Leave a Reply

Your email address will not be published. Required fields are marked *

English
Exit mobile version