This module contains functions that belong to two different categories:

1) Functions that use the underlying operating system facilities to perform name resolution, and that do not necessarily do any network communication. This category contains only one function: lookup. Developers looking to perform name resolution in the same way that other applications on the same operating system behave should use lookup.

2) Functions that connect to an actual DNS server to perform name resolution, and that always use the network to perform DNS queries. This category contains all functions in the dns module but lookup. These functions do not use the same set of configuration files than what lookup uses. For instance, they do not use the configuration from /etc/hosts. These functions should be used by developers who do not want to use the underlying operating system's facilities for name resolution, and instead want to always perform DNS queries.

Static variables

staticread onlyADDRCONFIG:Int

A flag passed in the hints argument of lookup method.

Returned address types are determined by the types of addresses supported by the current system. For example, IPv4 addresses are only returned if the current system has at least one IPv4 address configured. Loopback addresses are not considered.

staticread onlyV4MAPPED:Int

A flag passed in the hints argument of lookup method.

If the IPv6 family was specified, but no IPv6 addresses were found, then return IPv4 mapped IPv6 addresses. Note that it is not supported on some operating systems (e.g FreeBSD 10.1).

Static methods

staticgetServers():Array<String>

Returns an array of IP addresses as strings that are currently being used for resolution.

staticlookup(hostname:String, callback:DnsLookupCallbackSingle):Void

staticlookup(hostname:String, options:EitherType<DnsAddressFamily, DnsLookupOptions>, callback:EitherType<DnsLookupCallbackSingle, DnsLookupCallbackAll>):Void

Resolves a hostname (e.g. 'google.com') into the first found A (IPv4) or AAAA (IPv6) record.

If options is not provided, then IP v4 and v6 addresses are both valid.

The family can be the integer 4 or 6. Defaults to null that indicates both Ip v4 and v6 address family.

The callback has arguments (err, address, family). The address argument is a string representation of a IP v4 or v6 address. The family argument is either the integer 4 or 6 and denotes the family of address (not necessarily the value initially passed to lookup).

With the all option set, the arguments change to (err, addresses), with addresses being an array of objects with the properties address and family.

Keep in mind that err.code will be set to 'ENOENT' not only when the hostname does not exist but also when the lookup fails in other ways such as no available file descriptors.

lookup doesn't necessarily have anything to do with the DNS protocol. It's only an operating system facility that can associate name with addresses, and vice versa.

staticlookupService(address:String, port:Int, callback:(DnsError, String, String) ‑> Void):Void

Resolves the given address and port into a hostname and service using getnameinfo.

The callback has arguments (err, hostname, service). The hostname and service arguments are strings (e.g. 'localhost' and 'http' respectively).

On error, err is an Error object, where err.code is the error code.

staticresolve(hostname:String, rrtype:DnsRrtype, callback:(DnsError, Array<DnsResolvedAddress>) ‑> Void):Void

staticresolve(hostname:String, callback:(DnsError, Array<DnsResolvedAddress>) ‑> Void):Void

Resolves a hostname (e.g. 'google.com') into an array of the record types specified by rrtype.

The callback has arguments (err, addresses). The type of each item in addresses is determined by the record type, and described in the documentation for the corresponding lookup methods below.

On error, err is an Error object, where err.code is the error code.

staticresolve4(hostname:String, callback:(DnsError, Array<String>) ‑> Void):Void

The same as resolve, but only for IPv4 queries (A records). addresses is an array of IPv4 addresses (e.g. ['74.125.79.104', '74.125.79.105', '74.125.79.106']).

staticresolve6(hostname:String, callback:(DnsError, Array<String>) ‑> Void):Void

The same as resolve4 except for IPv6 queries (an AAAA query).

staticresolveCname(hostname:String, callback:(DnsError, Array<String>) ‑> Void):Void

The same as resolve, but only for canonical name records (CNAME records). addresses is an array of the canonical name records available for hostname (e.g., ['bar.example.com']).

staticresolveMx(hostname:String, callback:(DnsError, Array<DnsResolvedAddressMX>) ‑> Void):Void

The same as resolve, but only for mail exchange queries (MX records). addresses is an array of MX records, each with a priority and an exchange attribute (e.g. [{'priority': 10, 'exchange': 'mx.example.com'},...]).

staticresolveNs(hostname:String, callback:(DnsError, Array<String>) ‑> Void):Void

The same as resolve, but only for name server records (NS records). addresses is an array of the name server records available for hostname (e.g., ['ns1.example.com', 'ns2.example.com']).

staticresolvePtr(hostname:String, callback:(DnsError, Array<String>) ‑> Void):Void

Uses the DNS protocol to resolve pointer records (PTR records) for the hostname. The addresses argument passed to the callback function will be an array of strings containing the reply records.

staticresolveSoa(hostname:String, callback:(DnsError, DnsResolvedAddressSOA) ‑> Void):Void

The same as resolve, but only for start of authority record queries (SOA record).

addresses is an object with the following structure: { nsname: 'ns.example.com', hostmaster: 'root.example.com', serial: 2013101809, refresh: 10000, retry: 2400, expire: 604800, minttl: 3600 }

staticresolveSrv(hostname:String, callback:(DnsError, Array<DnsResolvedAddressSRV>) ‑> Void):Void

The same as resolve, but only for service records (SRV records). addresses is an array of the SRV records available for hostname. Properties of SRV records are priority, weight, port, and name (e.g., [{'priority': 10, 'weight': 5, 'port': 21223, 'name': 'service.example.com'}, ...]).

staticresolveTxt(hostname:String, callback:(DnsError, Array<Array<String>>) ‑> Void):Void

The same as resolve, but only for text queries (TXT records). addresses is a 2-d array of the text records available for hostname (e.g., [ ['v=spf1 ip4:0.0.0.0 ', '~all' ] ]). Each sub-array contains TXT chunks of one record. Depending on the use case, the could be either joined together or treated separately.

staticreverse(ip:String, callback:(DnsError, Array<String>) ‑> Void):Void

Reverse resolves an ip address to an array of hostnames. The callback has arguments (err, hostname).

staticsetServers(servers:Array<String>):Void

Given an array of IP addresses as strings, set them as the servers to use for resolving.

If you specify a port with the address it will be stripped, as the underlying library doesn't support that.

This will throw if you pass invalid input.