{
  "source": "doc/api/dns.markdown",
  "modules": [
    {
      "textRaw": "DNS",
      "name": "dns",
      "stability": 3,
      "stabilityText": "Stable",
      "desc": "<p>Use <code>require(&#39;dns&#39;)</code> to access this module. All methods in the dns module\nuse C-Ares except for <code>dns.lookup</code> which uses <code>getaddrinfo(3)</code> in a thread\npool. C-Ares is much faster than <code>getaddrinfo</code> but the system resolver is\nmore consistent with how other programs operate. When a user does\n<code>net.connect(80, &#39;google.com&#39;)</code> or <code>http.get({ host: &#39;google.com&#39; })</code> the\n<code>dns.lookup</code> method is used. Users who need to do a large number of lookups\nquickly should use the methods that go through C-Ares.\n\n</p>\n<p>Here is an example which resolves <code>&#39;www.google.com&#39;</code> then reverse\nresolves the IP addresses which are returned.\n\n</p>\n<pre><code>var dns = require(&#39;dns&#39;);\n\ndns.resolve4(&#39;www.google.com&#39;, function (err, addresses) {\n  if (err) throw err;\n\n  console.log(&#39;addresses: &#39; + JSON.stringify(addresses));\n\n  addresses.forEach(function (a) {\n    dns.reverse(a, function (err, hostnames) {\n      if (err) {\n        throw err;\n      }\n\n      console.log(&#39;reverse for &#39; + a + &#39;: &#39; + JSON.stringify(hostnames));\n    });\n  });\n});</code></pre>\n",
      "methods": [
        {
          "textRaw": "dns.lookup(hostname, [options], callback)",
          "type": "method",
          "name": "lookup",
          "desc": "<p>Resolves a hostname (e.g. <code>&#39;google.com&#39;</code>) into the first found A (IPv4) or\nAAAA (IPv6) record. <code>options</code> can be an object or integer. If <code>options</code> is\nnot provided, then IP v4 and v6 addresses are both valid. If <code>options</code> is\nan integer, then it must be <code>4</code> or <code>6</code>.\n\n</p>\n<p>Alternatively, <code>options</code> can be an object containing two properties,\n<code>family</code> and <code>hints</code>. Both properties are optional. If <code>family</code> is provided,\nit must be the integer <code>4</code> or <code>6</code>. If <code>family</code> is not provided then IP v4\nand v6 addresses are accepted. The <code>hints</code> field, if present, should be one\nor more of the supported <code>getaddrinfo</code> flags. If <code>hints</code> is not provided,\nthen no flags are passed to <code>getaddrinfo</code>. Multiple flags can be passed\nthrough <code>hints</code> by logically <code>OR</code>ing their values. An example usage of\n<code>options</code> is shown below.\n\n</p>\n<pre><code>{\n  family: 4,\n  hints: dns.ADDRCONFIG | dns.V4MAPPED\n}</code></pre>\n<p>See <a href=\"#dns_supported_getaddrinfo_flags\">supported <code>getaddrinfo</code> flags</a> below for\nmore information on supported flags.\n\n</p>\n<p>The callback has arguments <code>(err, address, family)</code>.  The <code>address</code> argument\nis a string representation of a IP v4 or v6 address. The <code>family</code> argument\nis either the integer 4 or 6 and denotes the family of <code>address</code> (not\nnecessarily the value initially passed to <code>lookup</code>).\n\n</p>\n<p>On error, <code>err</code> is an <code>Error</code> object, where <code>err.code</code> is the error code.\nKeep in mind that <code>err.code</code> will be set to <code>&#39;ENOENT&#39;</code> not only when\nthe hostname does not exist but also when the lookup fails in other ways\nsuch as no available file descriptors.\n\n\n</p>\n",
          "signatures": [
            {
              "params": [
                {
                  "name": "hostname"
                },
                {
                  "name": "options",
                  "optional": true
                },
                {
                  "name": "callback"
                }
              ]
            }
          ]
        }
      ],
      "type": "module",
      "displayName": "DNS"
    }
  ],
  "methods": [
    {
      "textRaw": "dns.lookupService(address, port, callback)",
      "type": "method",
      "name": "lookupService",
      "desc": "<p>Resolves the given address and port into a hostname and service using\n<code>getnameinfo</code>.\n\n</p>\n<p>The callback has arguments <code>(err, hostname, service)</code>. The <code>hostname</code> and\n<code>service</code> arguments are strings (e.g. <code>&#39;localhost&#39;</code> and <code>&#39;http&#39;</code> respectively).\n\n</p>\n<p>On error, <code>err</code> is an <code>Error</code> object, where <code>err.code</code> is the error code.\n\n\n</p>\n",
      "methods": [
        {
          "textRaw": "dns.resolve(hostname, [rrtype], callback)",
          "type": "method",
          "name": "resolve",
          "desc": "<p>Resolves a hostname (e.g. <code>&#39;google.com&#39;</code>) into an array of the record types\nspecified by rrtype.\n\n</p>\n<p>Valid rrtypes are:\n\n</p>\n<ul>\n<li><code>&#39;A&#39;</code> (IPV4 addresses, default)</li>\n<li><code>&#39;AAAA&#39;</code> (IPV6 addresses)</li>\n<li><code>&#39;MX&#39;</code> (mail exchange records)</li>\n<li><code>&#39;TXT&#39;</code> (text records)</li>\n<li><code>&#39;SRV&#39;</code> (SRV records)</li>\n<li><code>&#39;PTR&#39;</code> (used for reverse IP lookups)</li>\n<li><code>&#39;NS&#39;</code> (name server records)</li>\n<li><code>&#39;CNAME&#39;</code> (canonical name records)</li>\n<li><code>&#39;SOA&#39;</code> (start of authority record)</li>\n</ul>\n<p>The callback has arguments <code>(err, addresses)</code>.  The type of each item\nin <code>addresses</code> is determined by the record type, and described in the\ndocumentation for the corresponding lookup methods below.\n\n</p>\n<p>On error, <code>err</code> is an <code>Error</code> object, where <code>err.code</code> is\none of the error codes listed below.\n\n\n</p>\n",
          "signatures": [
            {
              "params": [
                {
                  "name": "hostname"
                },
                {
                  "name": "rrtype",
                  "optional": true
                },
                {
                  "name": "callback"
                }
              ]
            }
          ]
        },
        {
          "textRaw": "dns.resolve4(hostname, callback)",
          "type": "method",
          "name": "resolve4",
          "desc": "<p>The same as <code>dns.resolve()</code>, but only for IPv4 queries (<code>A</code> records).\n<code>addresses</code> is an array of IPv4 addresses (e.g.\n<code>[&#39;74.125.79.104&#39;, &#39;74.125.79.105&#39;, &#39;74.125.79.106&#39;]</code>).\n\n</p>\n",
          "signatures": [
            {
              "params": [
                {
                  "name": "hostname"
                },
                {
                  "name": "callback"
                }
              ]
            }
          ]
        },
        {
          "textRaw": "dns.resolve6(hostname, callback)",
          "type": "method",
          "name": "resolve6",
          "desc": "<p>The same as <code>dns.resolve4()</code> except for IPv6 queries (an <code>AAAA</code> query).\n\n\n</p>\n",
          "signatures": [
            {
              "params": [
                {
                  "name": "hostname"
                },
                {
                  "name": "callback"
                }
              ]
            }
          ]
        },
        {
          "textRaw": "dns.resolveMx(hostname, callback)",
          "type": "method",
          "name": "resolveMx",
          "desc": "<p>The same as <code>dns.resolve()</code>, but only for mail exchange queries (<code>MX</code> records).\n\n</p>\n<p><code>addresses</code> is an array of MX records, each with a priority and an exchange\nattribute (e.g. <code>[{&#39;priority&#39;: 10, &#39;exchange&#39;: &#39;mx.example.com&#39;},...]</code>).\n\n</p>\n",
          "signatures": [
            {
              "params": [
                {
                  "name": "hostname"
                },
                {
                  "name": "callback"
                }
              ]
            }
          ]
        },
        {
          "textRaw": "dns.resolveTxt(hostname, callback)",
          "type": "method",
          "name": "resolveTxt",
          "desc": "<p>The same as <code>dns.resolve()</code>, but only for text queries (<code>TXT</code> records).\n<code>addresses</code> is an 2-d array of the text records available for <code>hostname</code> (e.g.,\n<code>[ [&#39;v=spf1 ip4:0.0.0.0 &#39;, &#39;~all&#39; ] ]</code>). Each sub-array contains TXT chunks of\none record. Depending on the use case, the could be either joined together or\ntreated separately.\n\n</p>\n",
          "signatures": [
            {
              "params": [
                {
                  "name": "hostname"
                },
                {
                  "name": "callback"
                }
              ]
            }
          ]
        },
        {
          "textRaw": "dns.resolveSrv(hostname, callback)",
          "type": "method",
          "name": "resolveSrv",
          "desc": "<p>The same as <code>dns.resolve()</code>, but only for service records (<code>SRV</code> records).\n<code>addresses</code> is an array of the SRV records available for <code>hostname</code>. Properties\nof SRV records are priority, weight, port, and name (e.g.,\n<code>[{&#39;priority&#39;: 10, &#39;weight&#39;: 5, &#39;port&#39;: 21223, &#39;name&#39;: &#39;service.example.com&#39;}, ...]</code>).\n\n</p>\n",
          "signatures": [
            {
              "params": [
                {
                  "name": "hostname"
                },
                {
                  "name": "callback"
                }
              ]
            }
          ]
        },
        {
          "textRaw": "dns.resolveSoa(hostname, callback)",
          "type": "method",
          "name": "resolveSoa",
          "desc": "<p>The same as <code>dns.resolve()</code>, but only for start of authority record queries\n(<code>SOA</code> record).\n\n</p>\n<p><code>addresses</code> is an object with the following structure:\n\n</p>\n<pre><code>{\n  nsname: &#39;ns.example.com&#39;,\n  hostmaster: &#39;root.example.com&#39;,\n  serial: 2013101809,\n  refresh: 10000,\n  retry: 2400,\n  expire: 604800,\n  minttl: 3600\n}</code></pre>\n",
          "signatures": [
            {
              "params": [
                {
                  "name": "hostname"
                },
                {
                  "name": "callback"
                }
              ]
            }
          ]
        },
        {
          "textRaw": "dns.resolveNs(hostname, callback)",
          "type": "method",
          "name": "resolveNs",
          "desc": "<p>The same as <code>dns.resolve()</code>, but only for name server records (<code>NS</code> records).\n<code>addresses</code> is an array of the name server records available for <code>hostname</code>\n(e.g., <code>[&#39;ns1.example.com&#39;, &#39;ns2.example.com&#39;]</code>).\n\n</p>\n",
          "signatures": [
            {
              "params": [
                {
                  "name": "hostname"
                },
                {
                  "name": "callback"
                }
              ]
            }
          ]
        },
        {
          "textRaw": "dns.resolveCname(hostname, callback)",
          "type": "method",
          "name": "resolveCname",
          "desc": "<p>The same as <code>dns.resolve()</code>, but only for canonical name records (<code>CNAME</code>\nrecords). <code>addresses</code> is an array of the canonical name records available for\n<code>hostname</code> (e.g., <code>[&#39;bar.example.com&#39;]</code>).\n\n</p>\n",
          "signatures": [
            {
              "params": [
                {
                  "name": "hostname"
                },
                {
                  "name": "callback"
                }
              ]
            }
          ]
        },
        {
          "textRaw": "dns.reverse(ip, callback)",
          "type": "method",
          "name": "reverse",
          "desc": "<p>Reverse resolves an ip address to an array of hostnames.\n\n</p>\n<p>The callback has arguments <code>(err, hostnames)</code>.\n\n</p>\n<p>On error, <code>err</code> is an <code>Error</code> object, where <code>err.code</code> is\none of the error codes listed below.\n\n</p>\n",
          "signatures": [
            {
              "params": [
                {
                  "name": "ip"
                },
                {
                  "name": "callback"
                }
              ]
            }
          ]
        },
        {
          "textRaw": "dns.getServers()",
          "type": "method",
          "name": "getServers",
          "desc": "<p>Returns an array of IP addresses as strings that are currently being used for\nresolution\n\n</p>\n",
          "signatures": [
            {
              "params": []
            }
          ]
        },
        {
          "textRaw": "dns.setServers(servers)",
          "type": "method",
          "name": "setServers",
          "desc": "<p>Given an array of IP addresses as strings, set them as the servers to use for\nresolving\n\n</p>\n<p>If you specify a port with the address it will be stripped, as the underlying\nlibrary doesn&#39;t support that.\n\n</p>\n<p>This will throw if you pass invalid input.\n\n</p>\n",
          "signatures": [
            {
              "params": [
                {
                  "name": "servers"
                }
              ]
            }
          ]
        }
      ],
      "modules": [
        {
          "textRaw": "Error codes",
          "name": "error_codes",
          "desc": "<p>Each DNS query can return one of the following error codes:\n\n</p>\n<ul>\n<li><code>dns.NODATA</code>: DNS server returned answer with no data.</li>\n<li><code>dns.FORMERR</code>: DNS server claims query was misformatted.</li>\n<li><code>dns.SERVFAIL</code>: DNS server returned general failure.</li>\n<li><code>dns.NOTFOUND</code>: Domain name not found.</li>\n<li><code>dns.NOTIMP</code>: DNS server does not implement requested operation.</li>\n<li><code>dns.REFUSED</code>: DNS server refused query.</li>\n<li><code>dns.BADQUERY</code>: Misformatted DNS query.</li>\n<li><code>dns.BADNAME</code>: Misformatted hostname.</li>\n<li><code>dns.BADFAMILY</code>: Unsupported address family.</li>\n<li><code>dns.BADRESP</code>: Misformatted DNS reply.</li>\n<li><code>dns.CONNREFUSED</code>: Could not contact DNS servers.</li>\n<li><code>dns.TIMEOUT</code>: Timeout while contacting DNS servers.</li>\n<li><code>dns.EOF</code>: End of file.</li>\n<li><code>dns.FILE</code>: Error reading file.</li>\n<li><code>dns.NOMEM</code>: Out of memory.</li>\n<li><code>dns.DESTRUCTION</code>: Channel is being destroyed.</li>\n<li><code>dns.BADSTR</code>: Misformatted string.</li>\n<li><code>dns.BADFLAGS</code>: Illegal flags specified.</li>\n<li><code>dns.NONAME</code>: Given hostname is not numeric.</li>\n<li><code>dns.BADHINTS</code>: Illegal hints flags specified.</li>\n<li><code>dns.NOTINITIALIZED</code>: c-ares library initialization not yet performed.</li>\n<li><code>dns.LOADIPHLPAPI</code>: Error loading iphlpapi.dll.</li>\n<li><code>dns.ADDRGETNETWORKPARAMS</code>: Could not find GetNetworkParams function.</li>\n<li><code>dns.CANCELLED</code>: DNS query cancelled.</li>\n</ul>\n",
          "type": "module",
          "displayName": "Error codes"
        },
        {
          "textRaw": "Supported getaddrinfo flags",
          "name": "supported_getaddrinfo_flags",
          "desc": "<p>The following flags can be passed as hints to <code>dns.lookup</code>.\n\n</p>\n<ul>\n<li><code>dns.ADDRCONFIG</code>: Returned address types are determined by the types\nof addresses supported by the current system. For example, IPv4 addresses\nare only returned if the current system has at least one IPv4 address\nconfigured. Loopback addresses are not considered.</li>\n<li><code>dns.V4MAPPED</code>: If the IPv6 family was specified, but no IPv6 addresses\nwere found, then return IPv4 mapped IPv6 addresses.</li>\n</ul>\n",
          "type": "module",
          "displayName": "Supported getaddrinfo flags"
        }
      ],
      "signatures": [
        {
          "params": [
            {
              "name": "address"
            },
            {
              "name": "port"
            },
            {
              "name": "callback"
            }
          ]
        }
      ]
    }
  ]
}
