Bun

Node.js module

dns

The 'node:dns' module provides DNS lookup and resolution services. It supports synchronous and asynchronous methods to resolve host names, addresses, and service records.

Functions include lookup, resolve, reverse, and others for fetching various DNS record types like A, AAAA, CNAME, MX, PTR, SRV, and TXT.

Works in Bun

Fully implemented. > 90% of Node.js's test suite passes.

  • class Resolver

    An independent resolver for DNS requests.

    Creating a new resolver uses the default server settings. Setting the servers used for a resolver using resolver.setServers() does not affect other resolvers:

    import { Resolver } from 'node:dns';
    const resolver = new Resolver();
    resolver.setServers(['4.4.4.4']);
    
    // This request will use the server at 4.4.4.4, independent of global settings.
    resolver.resolve4('example.org', (err, addresses) => {
      // ...
    });
    

    The following methods from the node:dns module are available:

    • resolver.getServers()
    • resolver.resolve()
    • resolver.resolve4()
    • resolver.resolve6()
    • resolver.resolveAny()
    • resolver.resolveCaa()
    • resolver.resolveCname()
    • resolver.resolveMx()
    • resolver.resolveNaptr()
    • resolver.resolveNs()
    • resolver.resolvePtr()
    • resolver.resolveSoa()
    • resolver.resolveSrv()
    • resolver.resolveTxt()
    • resolver.reverse()
    • resolver.setServers()
  • const ADDRCONFIG: number

    Limits returned address types to the types of non-loopback addresses configured on the system. For example, IPv4 addresses are only returned if the current system has at least one IPv4 address configured.

  • const ADDRGETNETWORKPARAMS: 'EADDRGETNETWORKPARAMS'
  • const ALL: number

    If dns.V4MAPPED is specified, return resolved IPv6 addresses as well as IPv4 mapped IPv6 addresses.

  • const BADFAMILY: 'EBADFAMILY'
  • const BADFLAGS: 'EBADFLAGS'
  • const BADHINTS: 'EBADHINTS'
  • const BADNAME: 'EBADNAME'
  • const BADQUERY: 'EBADQUERY'
  • const BADRESP: 'EBADRESP'
  • const BADSTR: 'EBADSTR'
  • const CANCELLED: 'ECANCELLED'
  • const CONNREFUSED: 'ECONNREFUSED'
  • const DESTRUCTION: 'EDESTRUCTION'
  • const EOF: 'EOF'
  • const FILE: 'EFILE'
  • const FORMERR: 'EFORMERR'
  • const LOADIPHLPAPI: 'ELOADIPHLPAPI'
  • const NODATA: 'ENODATA'
  • const NOMEM: 'ENOMEM'
  • const NONAME: 'ENONAME'
  • const NOTFOUND: 'ENOTFOUND'
  • const NOTIMP: 'ENOTIMP'
  • const NOTINITIALIZED: 'ENOTINITIALIZED'
  • const REFUSED: 'EREFUSED'
  • const SERVFAIL: 'ESERVFAIL'
  • const TIMEOUT: 'ETIMEOUT'
  • const V4MAPPED: number

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

  • function getDefaultResultOrder(): 'ipv4first' | 'ipv6first' | 'verbatim';

    Get the default value for order in lookup and dnsPromises.lookup(). The value could be:

    • ipv4first: for order defaulting to ipv4first.
    • ipv6first: for order defaulting to ipv6first.
    • verbatim: for order defaulting to verbatim.
  • function getServers(): string[];

    Returns an array of IP address strings, formatted according to RFC 5952, that are currently configured for DNS resolution. A string will include a port section if a custom port is used.

    [
      '4.4.4.4',
      '2001:4860:4860::8888',
      '4.4.4.4:1053',
      '[2001:4860:4860::8888]:1053',
    ]
    
  • function lookup(
    hostname: string,
    family: number,
    callback: (err: null | ErrnoException, address: string, family: number) => void
    ): void;

    Resolves a host name (e.g. 'nodejs.org') into the first found A (IPv4) or AAAA (IPv6) record. All option properties are optional. If options is an integer, then it must be 4 or 6 – if options is 0 or not provided, then IPv4 and IPv6 addresses are both returned if found.

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

    On error, err is an Error object, where err.code is the error code. Keep in mind that err.code will be set to 'ENOTFOUND' not only when the host name does not exist but also when the lookup fails in other ways such as no available file descriptors.

    dns.lookup() does not necessarily have anything to do with the DNS protocol. The implementation uses an operating system facility that can associate names with addresses and vice versa. This implementation can have subtle but important consequences on the behavior of any Node.js program. Please take some time to consult the Implementation considerations section before using dns.lookup().

    Example usage:

    import dns from 'node:dns';
    const options = {
      family: 6,
      hints: dns.ADDRCONFIG | dns.V4MAPPED,
    };
    dns.lookup('example.com', options, (err, address, family) =>
      console.log('address: %j family: IPv%s', address, family));
    // address: "2606:2800:220:1:248:1893:25c8:1946" family: IPv6
    
    // When options.all is true, the result will be an Array.
    options.all = true;
    dns.lookup('example.com', options, (err, addresses) =>
      console.log('addresses: %j', addresses));
    // addresses: [{"address":"2606:2800:220:1:248:1893:25c8:1946","family":6}]
    

    If this method is invoked as its util.promisify() ed version, and all is not set to true, it returns a Promise for an Object with address and family properties.

    function lookup(
    hostname: string,
    callback: (err: null | ErrnoException, address: string, family: number) => void
    ): void;

    Resolves a host name (e.g. 'nodejs.org') into the first found A (IPv4) or AAAA (IPv6) record. All option properties are optional. If options is an integer, then it must be 4 or 6 – if options is 0 or not provided, then IPv4 and IPv6 addresses are both returned if found.

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

    On error, err is an Error object, where err.code is the error code. Keep in mind that err.code will be set to 'ENOTFOUND' not only when the host name does not exist but also when the lookup fails in other ways such as no available file descriptors.

    dns.lookup() does not necessarily have anything to do with the DNS protocol. The implementation uses an operating system facility that can associate names with addresses and vice versa. This implementation can have subtle but important consequences on the behavior of any Node.js program. Please take some time to consult the Implementation considerations section before using dns.lookup().

    Example usage:

    import dns from 'node:dns';
    const options = {
      family: 6,
      hints: dns.ADDRCONFIG | dns.V4MAPPED,
    };
    dns.lookup('example.com', options, (err, address, family) =>
      console.log('address: %j family: IPv%s', address, family));
    // address: "2606:2800:220:1:248:1893:25c8:1946" family: IPv6
    
    // When options.all is true, the result will be an Array.
    options.all = true;
    dns.lookup('example.com', options, (err, addresses) =>
      console.log('addresses: %j', addresses));
    // addresses: [{"address":"2606:2800:220:1:248:1893:25c8:1946","family":6}]
    

    If this method is invoked as its util.promisify() ed version, and all is not set to true, it returns a Promise for an Object with address and family properties.

    function lookup(
    hostname: string,
    callback: (err: null | ErrnoException, addresses: LookupAddress[]) => void
    ): void;

    Resolves a host name (e.g. 'nodejs.org') into the first found A (IPv4) or AAAA (IPv6) record. All option properties are optional. If options is an integer, then it must be 4 or 6 – if options is 0 or not provided, then IPv4 and IPv6 addresses are both returned if found.

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

    On error, err is an Error object, where err.code is the error code. Keep in mind that err.code will be set to 'ENOTFOUND' not only when the host name does not exist but also when the lookup fails in other ways such as no available file descriptors.

    dns.lookup() does not necessarily have anything to do with the DNS protocol. The implementation uses an operating system facility that can associate names with addresses and vice versa. This implementation can have subtle but important consequences on the behavior of any Node.js program. Please take some time to consult the Implementation considerations section before using dns.lookup().

    Example usage:

    import dns from 'node:dns';
    const options = {
      family: 6,
      hints: dns.ADDRCONFIG | dns.V4MAPPED,
    };
    dns.lookup('example.com', options, (err, address, family) =>
      console.log('address: %j family: IPv%s', address, family));
    // address: "2606:2800:220:1:248:1893:25c8:1946" family: IPv6
    
    // When options.all is true, the result will be an Array.
    options.all = true;
    dns.lookup('example.com', options, (err, addresses) =>
      console.log('addresses: %j', addresses));
    // addresses: [{"address":"2606:2800:220:1:248:1893:25c8:1946","family":6}]
    

    If this method is invoked as its util.promisify() ed version, and all is not set to true, it returns a Promise for an Object with address and family properties.

    function lookup(
    hostname: string,
    options: LookupOptions,
    callback: (err: null | ErrnoException, address: string | LookupAddress[], family: number) => void
    ): void;

    Resolves a host name (e.g. 'nodejs.org') into the first found A (IPv4) or AAAA (IPv6) record. All option properties are optional. If options is an integer, then it must be 4 or 6 – if options is 0 or not provided, then IPv4 and IPv6 addresses are both returned if found.

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

    On error, err is an Error object, where err.code is the error code. Keep in mind that err.code will be set to 'ENOTFOUND' not only when the host name does not exist but also when the lookup fails in other ways such as no available file descriptors.

    dns.lookup() does not necessarily have anything to do with the DNS protocol. The implementation uses an operating system facility that can associate names with addresses and vice versa. This implementation can have subtle but important consequences on the behavior of any Node.js program. Please take some time to consult the Implementation considerations section before using dns.lookup().

    Example usage:

    import dns from 'node:dns';
    const options = {
      family: 6,
      hints: dns.ADDRCONFIG | dns.V4MAPPED,
    };
    dns.lookup('example.com', options, (err, address, family) =>
      console.log('address: %j family: IPv%s', address, family));
    // address: "2606:2800:220:1:248:1893:25c8:1946" family: IPv6
    
    // When options.all is true, the result will be an Array.
    options.all = true;
    dns.lookup('example.com', options, (err, addresses) =>
      console.log('addresses: %j', addresses));
    // addresses: [{"address":"2606:2800:220:1:248:1893:25c8:1946","family":6}]
    

    If this method is invoked as its util.promisify() ed version, and all is not set to true, it returns a Promise for an Object with address and family properties.

    function lookup(
    hostname: string,
    callback: (err: null | ErrnoException, address: string, family: number) => void
    ): void;

    Resolves a host name (e.g. 'nodejs.org') into the first found A (IPv4) or AAAA (IPv6) record. All option properties are optional. If options is an integer, then it must be 4 or 6 – if options is 0 or not provided, then IPv4 and IPv6 addresses are both returned if found.

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

    On error, err is an Error object, where err.code is the error code. Keep in mind that err.code will be set to 'ENOTFOUND' not only when the host name does not exist but also when the lookup fails in other ways such as no available file descriptors.

    dns.lookup() does not necessarily have anything to do with the DNS protocol. The implementation uses an operating system facility that can associate names with addresses and vice versa. This implementation can have subtle but important consequences on the behavior of any Node.js program. Please take some time to consult the Implementation considerations section before using dns.lookup().

    Example usage:

    import dns from 'node:dns';
    const options = {
      family: 6,
      hints: dns.ADDRCONFIG | dns.V4MAPPED,
    };
    dns.lookup('example.com', options, (err, address, family) =>
      console.log('address: %j family: IPv%s', address, family));
    // address: "2606:2800:220:1:248:1893:25c8:1946" family: IPv6
    
    // When options.all is true, the result will be an Array.
    options.all = true;
    dns.lookup('example.com', options, (err, addresses) =>
      console.log('addresses: %j', addresses));
    // addresses: [{"address":"2606:2800:220:1:248:1893:25c8:1946","family":6}]
    

    If this method is invoked as its util.promisify() ed version, and all is not set to true, it returns a Promise for an Object with address and family properties.

  • function lookupService(
    address: string,
    port: number,
    callback: (err: null | ErrnoException, hostname: string, service: string) => void
    ): void;

    Resolves the given address and port into a host name and service using the operating system's underlying getnameinfo implementation.

    If address is not a valid IP address, a TypeError will be thrown. The port will be coerced to a number. If it is not a legal port, a TypeError will be thrown.

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

    import dns from 'node:dns';
    dns.lookupService('127.0.0.1', 22, (err, hostname, service) => {
      console.log(hostname, service);
      // Prints: localhost ssh
    });
    

    If this method is invoked as its util.promisify() ed version, it returns a Promise for an Object with hostname and service properties.

  • function resolve(
    hostname: string,
    callback: (err: null | ErrnoException, addresses: string[]) => void
    ): void;

    Uses the DNS protocol to resolve a host name (e.g. 'nodejs.org') into an array of the resource records. The callback function has arguments (err, records). When successful, records will be an array of resource records. The type and structure of individual results varies based on rrtype:

    <omitted>

    On error, err is an Error object, where err.code is one of the DNS error codes.

    @param hostname

    Host name to resolve.

    function resolve(
    hostname: string,
    rrtype: 'A',
    callback: (err: null | ErrnoException, addresses: string[]) => void
    ): void;

    Uses the DNS protocol to resolve a host name (e.g. 'nodejs.org') into an array of the resource records. The callback function has arguments (err, records). When successful, records will be an array of resource records. The type and structure of individual results varies based on rrtype:

    <omitted>

    On error, err is an Error object, where err.code is one of the DNS error codes.

    @param hostname

    Host name to resolve.

    @param rrtype

    Resource record type.

    function resolve(
    hostname: string,
    rrtype: 'AAAA',
    callback: (err: null | ErrnoException, addresses: string[]) => void
    ): void;

    Uses the DNS protocol to resolve a host name (e.g. 'nodejs.org') into an array of the resource records. The callback function has arguments (err, records). When successful, records will be an array of resource records. The type and structure of individual results varies based on rrtype:

    <omitted>

    On error, err is an Error object, where err.code is one of the DNS error codes.

    @param hostname

    Host name to resolve.

    @param rrtype

    Resource record type.

    function resolve(
    hostname: string,
    rrtype: 'ANY',
    callback: (err: null | ErrnoException, addresses: AnyRecord[]) => void
    ): void;

    Uses the DNS protocol to resolve a host name (e.g. 'nodejs.org') into an array of the resource records. The callback function has arguments (err, records). When successful, records will be an array of resource records. The type and structure of individual results varies based on rrtype:

    <omitted>

    On error, err is an Error object, where err.code is one of the DNS error codes.

    @param hostname

    Host name to resolve.

    @param rrtype

    Resource record type.

    function resolve(
    hostname: string,
    rrtype: 'CNAME',
    callback: (err: null | ErrnoException, addresses: string[]) => void
    ): void;

    Uses the DNS protocol to resolve a host name (e.g. 'nodejs.org') into an array of the resource records. The callback function has arguments (err, records). When successful, records will be an array of resource records. The type and structure of individual results varies based on rrtype:

    <omitted>

    On error, err is an Error object, where err.code is one of the DNS error codes.

    @param hostname

    Host name to resolve.

    @param rrtype

    Resource record type.

    function resolve(
    hostname: string,
    rrtype: 'MX',
    callback: (err: null | ErrnoException, addresses: MxRecord[]) => void
    ): void;

    Uses the DNS protocol to resolve a host name (e.g. 'nodejs.org') into an array of the resource records. The callback function has arguments (err, records). When successful, records will be an array of resource records. The type and structure of individual results varies based on rrtype:

    <omitted>

    On error, err is an Error object, where err.code is one of the DNS error codes.

    @param hostname

    Host name to resolve.

    @param rrtype

    Resource record type.

    function resolve(
    hostname: string,
    rrtype: 'NAPTR',
    callback: (err: null | ErrnoException, addresses: NaptrRecord[]) => void
    ): void;

    Uses the DNS protocol to resolve a host name (e.g. 'nodejs.org') into an array of the resource records. The callback function has arguments (err, records). When successful, records will be an array of resource records. The type and structure of individual results varies based on rrtype:

    <omitted>

    On error, err is an Error object, where err.code is one of the DNS error codes.

    @param hostname

    Host name to resolve.

    @param rrtype

    Resource record type.

    function resolve(
    hostname: string,
    rrtype: 'NS',
    callback: (err: null | ErrnoException, addresses: string[]) => void
    ): void;

    Uses the DNS protocol to resolve a host name (e.g. 'nodejs.org') into an array of the resource records. The callback function has arguments (err, records). When successful, records will be an array of resource records. The type and structure of individual results varies based on rrtype:

    <omitted>

    On error, err is an Error object, where err.code is one of the DNS error codes.

    @param hostname

    Host name to resolve.

    @param rrtype

    Resource record type.

    function resolve(
    hostname: string,
    rrtype: 'PTR',
    callback: (err: null | ErrnoException, addresses: string[]) => void
    ): void;

    Uses the DNS protocol to resolve a host name (e.g. 'nodejs.org') into an array of the resource records. The callback function has arguments (err, records). When successful, records will be an array of resource records. The type and structure of individual results varies based on rrtype:

    <omitted>

    On error, err is an Error object, where err.code is one of the DNS error codes.

    @param hostname

    Host name to resolve.

    @param rrtype

    Resource record type.

    function resolve(
    hostname: string,
    rrtype: 'SOA',
    callback: (err: null | ErrnoException, addresses: SoaRecord) => void
    ): void;

    Uses the DNS protocol to resolve a host name (e.g. 'nodejs.org') into an array of the resource records. The callback function has arguments (err, records). When successful, records will be an array of resource records. The type and structure of individual results varies based on rrtype:

    <omitted>

    On error, err is an Error object, where err.code is one of the DNS error codes.

    @param hostname

    Host name to resolve.

    @param rrtype

    Resource record type.

    function resolve(
    hostname: string,
    rrtype: 'SRV',
    callback: (err: null | ErrnoException, addresses: SrvRecord[]) => void
    ): void;

    Uses the DNS protocol to resolve a host name (e.g. 'nodejs.org') into an array of the resource records. The callback function has arguments (err, records). When successful, records will be an array of resource records. The type and structure of individual results varies based on rrtype:

    <omitted>

    On error, err is an Error object, where err.code is one of the DNS error codes.

    @param hostname

    Host name to resolve.

    @param rrtype

    Resource record type.

    function resolve(
    hostname: string,
    rrtype: 'TXT',
    callback: (err: null | ErrnoException, addresses: string[][]) => void
    ): void;

    Uses the DNS protocol to resolve a host name (e.g. 'nodejs.org') into an array of the resource records. The callback function has arguments (err, records). When successful, records will be an array of resource records. The type and structure of individual results varies based on rrtype:

    <omitted>

    On error, err is an Error object, where err.code is one of the DNS error codes.

    @param hostname

    Host name to resolve.

    @param rrtype

    Resource record type.

    function resolve(
    hostname: string,
    rrtype: string,
    callback: (err: null | ErrnoException, addresses: string[] | SoaRecord | AnyRecord[] | MxRecord[] | NaptrRecord[] | SrvRecord[] | string[][]) => void
    ): void;

    Uses the DNS protocol to resolve a host name (e.g. 'nodejs.org') into an array of the resource records. The callback function has arguments (err, records). When successful, records will be an array of resource records. The type and structure of individual results varies based on rrtype:

    <omitted>

    On error, err is an Error object, where err.code is one of the DNS error codes.

    @param hostname

    Host name to resolve.

    @param rrtype

    Resource record type.

  • function resolve4(
    hostname: string,
    callback: (err: null | ErrnoException, addresses: string[]) => void
    ): void;

    Uses the DNS protocol to resolve a IPv4 addresses (A records) for the hostname. The addresses argument passed to the callback function will contain an array of IPv4 addresses (e.g.['74.125.79.104', '74.125.79.105', '74.125.79.106']).

    @param hostname

    Host name to resolve.

    function resolve4(
    hostname: string,
    callback: (err: null | ErrnoException, addresses: RecordWithTtl[]) => void
    ): void;

    Uses the DNS protocol to resolve a IPv4 addresses (A records) for the hostname. The addresses argument passed to the callback function will contain an array of IPv4 addresses (e.g.['74.125.79.104', '74.125.79.105', '74.125.79.106']).

    @param hostname

    Host name to resolve.

    function resolve4(
    hostname: string,
    options: ResolveOptions,
    callback: (err: null | ErrnoException, addresses: string[] | RecordWithTtl[]) => void
    ): void;

    Uses the DNS protocol to resolve a IPv4 addresses (A records) for the hostname. The addresses argument passed to the callback function will contain an array of IPv4 addresses (e.g.['74.125.79.104', '74.125.79.105', '74.125.79.106']).

    @param hostname

    Host name to resolve.

  • function resolve6(
    hostname: string,
    callback: (err: null | ErrnoException, addresses: string[]) => void
    ): void;

    Uses the DNS protocol to resolve IPv6 addresses (AAAA records) for the hostname. The addresses argument passed to the callback function will contain an array of IPv6 addresses.

    @param hostname

    Host name to resolve.

    function resolve6(
    hostname: string,
    callback: (err: null | ErrnoException, addresses: RecordWithTtl[]) => void
    ): void;

    Uses the DNS protocol to resolve IPv6 addresses (AAAA records) for the hostname. The addresses argument passed to the callback function will contain an array of IPv6 addresses.

    @param hostname

    Host name to resolve.

    function resolve6(
    hostname: string,
    options: ResolveOptions,
    callback: (err: null | ErrnoException, addresses: string[] | RecordWithTtl[]) => void
    ): void;

    Uses the DNS protocol to resolve IPv6 addresses (AAAA records) for the hostname. The addresses argument passed to the callback function will contain an array of IPv6 addresses.

    @param hostname

    Host name to resolve.

  • function resolveAny(
    hostname: string,
    callback: (err: null | ErrnoException, addresses: AnyRecord[]) => void
    ): void;

    Uses the DNS protocol to resolve all records (also known as ANY or * query). The ret argument passed to the callback function will be an array containing various types of records. Each object has a property type that indicates the type of the current record. And depending on the type, additional properties will be present on the object:

    <omitted>

    Here is an example of the ret object passed to the callback:

    [ { type: 'A', address: '127.0.0.1', ttl: 299 },
      { type: 'CNAME', value: 'example.com' },
      { type: 'MX', exchange: 'alt4.aspmx.l.example.com', priority: 50 },
      { type: 'NS', value: 'ns1.example.com' },
      { type: 'TXT', entries: [ 'v=spf1 include:_spf.example.com ~all' ] },
      { type: 'SOA',
        nsname: 'ns1.example.com',
        hostmaster: 'admin.example.com',
        serial: 156696742,
        refresh: 900,
        retry: 900,
        expire: 1800,
        minttl: 60 } ]
    

    DNS server operators may choose not to respond to ANY queries. It may be better to call individual methods like resolve4, resolveMx, and so on. For more details, see RFC 8482.

  • function resolveCaa(
    hostname: string,
    callback: (err: null | ErrnoException, records: CaaRecord[]) => void
    ): void;

    Uses the DNS protocol to resolve CAA records for the hostname. The addresses argument passed to the callback function will contain an array of certification authority authorization records available for the hostname (e.g. [{critical: 0, iodef: 'mailto:pki@example.com'}, {critical: 128, issue: 'pki.example.com'}]).

  • function resolveCname(
    hostname: string,
    callback: (err: null | ErrnoException, addresses: string[]) => void
    ): void;

    Uses the DNS protocol to resolve CNAME records for the hostname. The addresses argument passed to the callback function will contain an array of canonical name records available for the hostname (e.g. ['bar.example.com']).

  • function resolveMx(
    hostname: string,
    callback: (err: null | ErrnoException, addresses: MxRecord[]) => void
    ): void;

    Uses the DNS protocol to resolve mail exchange records (MX records) for the hostname. The addresses argument passed to the callback function will contain an array of objects containing both a priority and exchange property (e.g. [{priority: 10, exchange: 'mx.example.com'}, ...]).

  • function resolveNaptr(
    hostname: string,
    callback: (err: null | ErrnoException, addresses: NaptrRecord[]) => void
    ): void;

    Uses the DNS protocol to resolve regular expression-based records (NAPTR records) for the hostname. The addresses argument passed to the callback function will contain an array of objects with the following properties:

    • flags
    • service
    • regexp
    • replacement
    • order
    • preference
    {
      flags: 's',
      service: 'SIP+D2U',
      regexp: '',
      replacement: '_sip._udp.example.com',
      order: 30,
      preference: 100
    }
    
  • function resolveNs(
    hostname: string,
    callback: (err: null | ErrnoException, addresses: string[]) => void
    ): void;

    Uses the DNS protocol to resolve name server records (NS records) for the hostname. The addresses argument passed to the callback function will contain an array of name server records available for hostname (e.g. ['ns1.example.com', 'ns2.example.com']).

  • function resolvePtr(
    hostname: string,
    callback: (err: null | ErrnoException, addresses: 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.

  • function resolveSoa(
    hostname: string,
    callback: (err: null | ErrnoException, address: SoaRecord) => void
    ): void;

    Uses the DNS protocol to resolve a start of authority record (SOA record) for the hostname. The address argument passed to the callback function will be an object with the following properties:

    • nsname
    • hostmaster
    • serial
    • refresh
    • retry
    • expire
    • minttl
    {
      nsname: 'ns.example.com',
      hostmaster: 'root.example.com',
      serial: 2013101809,
      refresh: 10000,
      retry: 2400,
      expire: 604800,
      minttl: 3600
    }
    
  • function resolveSrv(
    hostname: string,
    callback: (err: null | ErrnoException, addresses: SrvRecord[]) => void
    ): void;

    Uses the DNS protocol to resolve service records (SRV records) for the hostname. The addresses argument passed to the callback function will be an array of objects with the following properties:

    • priority
    • weight
    • port
    • name
    {
      priority: 10,
      weight: 5,
      port: 21223,
      name: 'service.example.com'
    }
    
  • function resolveTxt(
    hostname: string,
    callback: (err: null | ErrnoException, addresses: string[][]) => void
    ): void;

    Uses the DNS protocol to resolve text queries (TXT records) for the hostname. The records argument passed to the callback function is a two-dimensional 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, these could be either joined together or treated separately.

  • function reverse(
    ip: string,
    callback: (err: null | ErrnoException, hostnames: string[]) => void
    ): void;

    Performs a reverse DNS query that resolves an IPv4 or IPv6 address to an array of host names.

    On error, err is an Error object, where err.code is one of the DNS error codes.

  • order: 'ipv4first' | 'ipv6first' | 'verbatim'
    ): void;

    Set the default value of order in lookup and dnsPromises.lookup(). The value could be:

    • ipv4first: sets default order to ipv4first.
    • ipv6first: sets default order to ipv6first.
    • verbatim: sets default order to verbatim.

    The default is verbatim and setDefaultResultOrder have higher priority than --dns-result-order. When using worker threads, setDefaultResultOrder from the main thread won't affect the default dns orders in workers.

    @param order

    must be 'ipv4first', 'ipv6first' or 'verbatim'.

  • function setServers(
    servers: readonly string[]
    ): void;

    Sets the IP address and port of servers to be used when performing DNS resolution. The servers argument is an array of RFC 5952 formatted addresses. If the port is the IANA default DNS port (53) it can be omitted.

    dns.setServers([
      '4.4.4.4',
      '[2001:4860:4860::8888]',
      '4.4.4.4:1053',
      '[2001:4860:4860::8888]:1053',
    ]);
    

    An error will be thrown if an invalid address is provided.

    The dns.setServers() method must not be called while a DNS query is in progress.

    The setServers method affects only resolve, dns.resolve*() and reverse (and specifically not lookup).

    This method works much like resolve.conf. That is, if attempting to resolve with the first server provided results in a NOTFOUND error, the resolve() method will not attempt to resolve with subsequent servers provided. Fallback DNS servers will only be used if the earlier ones time out or result in some other error.

    @param servers

Type definitions

  • function lookup(
    hostname: string,
    family: number,
    callback: (err: null | ErrnoException, address: string, family: number) => void
    ): void;

    Resolves a host name (e.g. 'nodejs.org') into the first found A (IPv4) or AAAA (IPv6) record. All option properties are optional. If options is an integer, then it must be 4 or 6 – if options is 0 or not provided, then IPv4 and IPv6 addresses are both returned if found.

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

    On error, err is an Error object, where err.code is the error code. Keep in mind that err.code will be set to 'ENOTFOUND' not only when the host name does not exist but also when the lookup fails in other ways such as no available file descriptors.

    dns.lookup() does not necessarily have anything to do with the DNS protocol. The implementation uses an operating system facility that can associate names with addresses and vice versa. This implementation can have subtle but important consequences on the behavior of any Node.js program. Please take some time to consult the Implementation considerations section before using dns.lookup().

    Example usage:

    import dns from 'node:dns';
    const options = {
      family: 6,
      hints: dns.ADDRCONFIG | dns.V4MAPPED,
    };
    dns.lookup('example.com', options, (err, address, family) =>
      console.log('address: %j family: IPv%s', address, family));
    // address: "2606:2800:220:1:248:1893:25c8:1946" family: IPv6
    
    // When options.all is true, the result will be an Array.
    options.all = true;
    dns.lookup('example.com', options, (err, addresses) =>
      console.log('addresses: %j', addresses));
    // addresses: [{"address":"2606:2800:220:1:248:1893:25c8:1946","family":6}]
    

    If this method is invoked as its util.promisify() ed version, and all is not set to true, it returns a Promise for an Object with address and family properties.

    function lookup(
    hostname: string,
    callback: (err: null | ErrnoException, address: string, family: number) => void
    ): void;

    Resolves a host name (e.g. 'nodejs.org') into the first found A (IPv4) or AAAA (IPv6) record. All option properties are optional. If options is an integer, then it must be 4 or 6 – if options is 0 or not provided, then IPv4 and IPv6 addresses are both returned if found.

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

    On error, err is an Error object, where err.code is the error code. Keep in mind that err.code will be set to 'ENOTFOUND' not only when the host name does not exist but also when the lookup fails in other ways such as no available file descriptors.

    dns.lookup() does not necessarily have anything to do with the DNS protocol. The implementation uses an operating system facility that can associate names with addresses and vice versa. This implementation can have subtle but important consequences on the behavior of any Node.js program. Please take some time to consult the Implementation considerations section before using dns.lookup().

    Example usage:

    import dns from 'node:dns';
    const options = {
      family: 6,
      hints: dns.ADDRCONFIG | dns.V4MAPPED,
    };
    dns.lookup('example.com', options, (err, address, family) =>
      console.log('address: %j family: IPv%s', address, family));
    // address: "2606:2800:220:1:248:1893:25c8:1946" family: IPv6
    
    // When options.all is true, the result will be an Array.
    options.all = true;
    dns.lookup('example.com', options, (err, addresses) =>
      console.log('addresses: %j', addresses));
    // addresses: [{"address":"2606:2800:220:1:248:1893:25c8:1946","family":6}]
    

    If this method is invoked as its util.promisify() ed version, and all is not set to true, it returns a Promise for an Object with address and family properties.

    function lookup(
    hostname: string,
    callback: (err: null | ErrnoException, addresses: LookupAddress[]) => void
    ): void;

    Resolves a host name (e.g. 'nodejs.org') into the first found A (IPv4) or AAAA (IPv6) record. All option properties are optional. If options is an integer, then it must be 4 or 6 – if options is 0 or not provided, then IPv4 and IPv6 addresses are both returned if found.

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

    On error, err is an Error object, where err.code is the error code. Keep in mind that err.code will be set to 'ENOTFOUND' not only when the host name does not exist but also when the lookup fails in other ways such as no available file descriptors.

    dns.lookup() does not necessarily have anything to do with the DNS protocol. The implementation uses an operating system facility that can associate names with addresses and vice versa. This implementation can have subtle but important consequences on the behavior of any Node.js program. Please take some time to consult the Implementation considerations section before using dns.lookup().

    Example usage:

    import dns from 'node:dns';
    const options = {
      family: 6,
      hints: dns.ADDRCONFIG | dns.V4MAPPED,
    };
    dns.lookup('example.com', options, (err, address, family) =>
      console.log('address: %j family: IPv%s', address, family));
    // address: "2606:2800:220:1:248:1893:25c8:1946" family: IPv6
    
    // When options.all is true, the result will be an Array.
    options.all = true;
    dns.lookup('example.com', options, (err, addresses) =>
      console.log('addresses: %j', addresses));
    // addresses: [{"address":"2606:2800:220:1:248:1893:25c8:1946","family":6}]
    

    If this method is invoked as its util.promisify() ed version, and all is not set to true, it returns a Promise for an Object with address and family properties.

    function lookup(
    hostname: string,
    options: LookupOptions,
    callback: (err: null | ErrnoException, address: string | LookupAddress[], family: number) => void
    ): void;

    Resolves a host name (e.g. 'nodejs.org') into the first found A (IPv4) or AAAA (IPv6) record. All option properties are optional. If options is an integer, then it must be 4 or 6 – if options is 0 or not provided, then IPv4 and IPv6 addresses are both returned if found.

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

    On error, err is an Error object, where err.code is the error code. Keep in mind that err.code will be set to 'ENOTFOUND' not only when the host name does not exist but also when the lookup fails in other ways such as no available file descriptors.

    dns.lookup() does not necessarily have anything to do with the DNS protocol. The implementation uses an operating system facility that can associate names with addresses and vice versa. This implementation can have subtle but important consequences on the behavior of any Node.js program. Please take some time to consult the Implementation considerations section before using dns.lookup().

    Example usage:

    import dns from 'node:dns';
    const options = {
      family: 6,
      hints: dns.ADDRCONFIG | dns.V4MAPPED,
    };
    dns.lookup('example.com', options, (err, address, family) =>
      console.log('address: %j family: IPv%s', address, family));
    // address: "2606:2800:220:1:248:1893:25c8:1946" family: IPv6
    
    // When options.all is true, the result will be an Array.
    options.all = true;
    dns.lookup('example.com', options, (err, addresses) =>
      console.log('addresses: %j', addresses));
    // addresses: [{"address":"2606:2800:220:1:248:1893:25c8:1946","family":6}]
    

    If this method is invoked as its util.promisify() ed version, and all is not set to true, it returns a Promise for an Object with address and family properties.

    function lookup(
    hostname: string,
    callback: (err: null | ErrnoException, address: string, family: number) => void
    ): void;

    Resolves a host name (e.g. 'nodejs.org') into the first found A (IPv4) or AAAA (IPv6) record. All option properties are optional. If options is an integer, then it must be 4 or 6 – if options is 0 or not provided, then IPv4 and IPv6 addresses are both returned if found.

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

    On error, err is an Error object, where err.code is the error code. Keep in mind that err.code will be set to 'ENOTFOUND' not only when the host name does not exist but also when the lookup fails in other ways such as no available file descriptors.

    dns.lookup() does not necessarily have anything to do with the DNS protocol. The implementation uses an operating system facility that can associate names with addresses and vice versa. This implementation can have subtle but important consequences on the behavior of any Node.js program. Please take some time to consult the Implementation considerations section before using dns.lookup().

    Example usage:

    import dns from 'node:dns';
    const options = {
      family: 6,
      hints: dns.ADDRCONFIG | dns.V4MAPPED,
    };
    dns.lookup('example.com', options, (err, address, family) =>
      console.log('address: %j family: IPv%s', address, family));
    // address: "2606:2800:220:1:248:1893:25c8:1946" family: IPv6
    
    // When options.all is true, the result will be an Array.
    options.all = true;
    dns.lookup('example.com', options, (err, addresses) =>
      console.log('addresses: %j', addresses));
    // addresses: [{"address":"2606:2800:220:1:248:1893:25c8:1946","family":6}]
    

    If this method is invoked as its util.promisify() ed version, and all is not set to true, it returns a Promise for an Object with address and family properties.

    namespace lookup

    • function lookupService(
      address: string,
      port: number,
      callback: (err: null | ErrnoException, hostname: string, service: string) => void
      ): void;

      Resolves the given address and port into a host name and service using the operating system's underlying getnameinfo implementation.

      If address is not a valid IP address, a TypeError will be thrown. The port will be coerced to a number. If it is not a legal port, a TypeError will be thrown.

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

      import dns from 'node:dns';
      dns.lookupService('127.0.0.1', 22, (err, hostname, service) => {
        console.log(hostname, service);
        // Prints: localhost ssh
      });
      

      If this method is invoked as its util.promisify() ed version, it returns a Promise for an Object with hostname and service properties.

      namespace lookupService

      • function resolve(
        hostname: string,
        callback: (err: null | ErrnoException, addresses: string[]) => void
        ): void;

        Uses the DNS protocol to resolve a host name (e.g. 'nodejs.org') into an array of the resource records. The callback function has arguments (err, records). When successful, records will be an array of resource records. The type and structure of individual results varies based on rrtype:

        <omitted>

        On error, err is an Error object, where err.code is one of the DNS error codes.

        @param hostname

        Host name to resolve.

        function resolve(
        hostname: string,
        rrtype: 'A',
        callback: (err: null | ErrnoException, addresses: string[]) => void
        ): void;

        Uses the DNS protocol to resolve a host name (e.g. 'nodejs.org') into an array of the resource records. The callback function has arguments (err, records). When successful, records will be an array of resource records. The type and structure of individual results varies based on rrtype:

        <omitted>

        On error, err is an Error object, where err.code is one of the DNS error codes.

        @param hostname

        Host name to resolve.

        @param rrtype

        Resource record type.

        function resolve(
        hostname: string,
        rrtype: 'AAAA',
        callback: (err: null | ErrnoException, addresses: string[]) => void
        ): void;

        Uses the DNS protocol to resolve a host name (e.g. 'nodejs.org') into an array of the resource records. The callback function has arguments (err, records). When successful, records will be an array of resource records. The type and structure of individual results varies based on rrtype:

        <omitted>

        On error, err is an Error object, where err.code is one of the DNS error codes.

        @param hostname

        Host name to resolve.

        @param rrtype

        Resource record type.

        function resolve(
        hostname: string,
        rrtype: 'ANY',
        callback: (err: null | ErrnoException, addresses: AnyRecord[]) => void
        ): void;

        Uses the DNS protocol to resolve a host name (e.g. 'nodejs.org') into an array of the resource records. The callback function has arguments (err, records). When successful, records will be an array of resource records. The type and structure of individual results varies based on rrtype:

        <omitted>

        On error, err is an Error object, where err.code is one of the DNS error codes.

        @param hostname

        Host name to resolve.

        @param rrtype

        Resource record type.

        function resolve(
        hostname: string,
        rrtype: 'CNAME',
        callback: (err: null | ErrnoException, addresses: string[]) => void
        ): void;

        Uses the DNS protocol to resolve a host name (e.g. 'nodejs.org') into an array of the resource records. The callback function has arguments (err, records). When successful, records will be an array of resource records. The type and structure of individual results varies based on rrtype:

        <omitted>

        On error, err is an Error object, where err.code is one of the DNS error codes.

        @param hostname

        Host name to resolve.

        @param rrtype

        Resource record type.

        function resolve(
        hostname: string,
        rrtype: 'MX',
        callback: (err: null | ErrnoException, addresses: MxRecord[]) => void
        ): void;

        Uses the DNS protocol to resolve a host name (e.g. 'nodejs.org') into an array of the resource records. The callback function has arguments (err, records). When successful, records will be an array of resource records. The type and structure of individual results varies based on rrtype:

        <omitted>

        On error, err is an Error object, where err.code is one of the DNS error codes.

        @param hostname

        Host name to resolve.

        @param rrtype

        Resource record type.

        function resolve(
        hostname: string,
        rrtype: 'NAPTR',
        callback: (err: null | ErrnoException, addresses: NaptrRecord[]) => void
        ): void;

        Uses the DNS protocol to resolve a host name (e.g. 'nodejs.org') into an array of the resource records. The callback function has arguments (err, records). When successful, records will be an array of resource records. The type and structure of individual results varies based on rrtype:

        <omitted>

        On error, err is an Error object, where err.code is one of the DNS error codes.

        @param hostname

        Host name to resolve.

        @param rrtype

        Resource record type.

        function resolve(
        hostname: string,
        rrtype: 'NS',
        callback: (err: null | ErrnoException, addresses: string[]) => void
        ): void;

        Uses the DNS protocol to resolve a host name (e.g. 'nodejs.org') into an array of the resource records. The callback function has arguments (err, records). When successful, records will be an array of resource records. The type and structure of individual results varies based on rrtype:

        <omitted>

        On error, err is an Error object, where err.code is one of the DNS error codes.

        @param hostname

        Host name to resolve.

        @param rrtype

        Resource record type.

        function resolve(
        hostname: string,
        rrtype: 'PTR',
        callback: (err: null | ErrnoException, addresses: string[]) => void
        ): void;

        Uses the DNS protocol to resolve a host name (e.g. 'nodejs.org') into an array of the resource records. The callback function has arguments (err, records). When successful, records will be an array of resource records. The type and structure of individual results varies based on rrtype:

        <omitted>

        On error, err is an Error object, where err.code is one of the DNS error codes.

        @param hostname

        Host name to resolve.

        @param rrtype

        Resource record type.

        function resolve(
        hostname: string,
        rrtype: 'SOA',
        callback: (err: null | ErrnoException, addresses: SoaRecord) => void
        ): void;

        Uses the DNS protocol to resolve a host name (e.g. 'nodejs.org') into an array of the resource records. The callback function has arguments (err, records). When successful, records will be an array of resource records. The type and structure of individual results varies based on rrtype:

        <omitted>

        On error, err is an Error object, where err.code is one of the DNS error codes.

        @param hostname

        Host name to resolve.

        @param rrtype

        Resource record type.

        function resolve(
        hostname: string,
        rrtype: 'SRV',
        callback: (err: null | ErrnoException, addresses: SrvRecord[]) => void
        ): void;

        Uses the DNS protocol to resolve a host name (e.g. 'nodejs.org') into an array of the resource records. The callback function has arguments (err, records). When successful, records will be an array of resource records. The type and structure of individual results varies based on rrtype:

        <omitted>

        On error, err is an Error object, where err.code is one of the DNS error codes.

        @param hostname

        Host name to resolve.

        @param rrtype

        Resource record type.

        function resolve(
        hostname: string,
        rrtype: 'TXT',
        callback: (err: null | ErrnoException, addresses: string[][]) => void
        ): void;

        Uses the DNS protocol to resolve a host name (e.g. 'nodejs.org') into an array of the resource records. The callback function has arguments (err, records). When successful, records will be an array of resource records. The type and structure of individual results varies based on rrtype:

        <omitted>

        On error, err is an Error object, where err.code is one of the DNS error codes.

        @param hostname

        Host name to resolve.

        @param rrtype

        Resource record type.

        function resolve(
        hostname: string,
        rrtype: string,
        callback: (err: null | ErrnoException, addresses: string[] | SoaRecord | AnyRecord[] | MxRecord[] | NaptrRecord[] | SrvRecord[] | string[][]) => void
        ): void;

        Uses the DNS protocol to resolve a host name (e.g. 'nodejs.org') into an array of the resource records. The callback function has arguments (err, records). When successful, records will be an array of resource records. The type and structure of individual results varies based on rrtype:

        <omitted>

        On error, err is an Error object, where err.code is one of the DNS error codes.

        @param hostname

        Host name to resolve.

        @param rrtype

        Resource record type.

        namespace resolve

        • function resolve4(
          hostname: string,
          callback: (err: null | ErrnoException, addresses: string[]) => void
          ): void;

          Uses the DNS protocol to resolve a IPv4 addresses (A records) for the hostname. The addresses argument passed to the callback function will contain an array of IPv4 addresses (e.g.['74.125.79.104', '74.125.79.105', '74.125.79.106']).

          @param hostname

          Host name to resolve.

          function resolve4(
          hostname: string,
          callback: (err: null | ErrnoException, addresses: RecordWithTtl[]) => void
          ): void;

          Uses the DNS protocol to resolve a IPv4 addresses (A records) for the hostname. The addresses argument passed to the callback function will contain an array of IPv4 addresses (e.g.['74.125.79.104', '74.125.79.105', '74.125.79.106']).

          @param hostname

          Host name to resolve.

          function resolve4(
          hostname: string,
          options: ResolveOptions,
          callback: (err: null | ErrnoException, addresses: string[] | RecordWithTtl[]) => void
          ): void;

          Uses the DNS protocol to resolve a IPv4 addresses (A records) for the hostname. The addresses argument passed to the callback function will contain an array of IPv4 addresses (e.g.['74.125.79.104', '74.125.79.105', '74.125.79.106']).

          @param hostname

          Host name to resolve.

          namespace resolve4

          • function resolve6(
            hostname: string,
            callback: (err: null | ErrnoException, addresses: string[]) => void
            ): void;

            Uses the DNS protocol to resolve IPv6 addresses (AAAA records) for the hostname. The addresses argument passed to the callback function will contain an array of IPv6 addresses.

            @param hostname

            Host name to resolve.

            function resolve6(
            hostname: string,
            callback: (err: null | ErrnoException, addresses: RecordWithTtl[]) => void
            ): void;

            Uses the DNS protocol to resolve IPv6 addresses (AAAA records) for the hostname. The addresses argument passed to the callback function will contain an array of IPv6 addresses.

            @param hostname

            Host name to resolve.

            function resolve6(
            hostname: string,
            options: ResolveOptions,
            callback: (err: null | ErrnoException, addresses: string[] | RecordWithTtl[]) => void
            ): void;

            Uses the DNS protocol to resolve IPv6 addresses (AAAA records) for the hostname. The addresses argument passed to the callback function will contain an array of IPv6 addresses.

            @param hostname

            Host name to resolve.

            namespace resolve6

            • function resolveAny(
              hostname: string,
              callback: (err: null | ErrnoException, addresses: AnyRecord[]) => void
              ): void;

              Uses the DNS protocol to resolve all records (also known as ANY or * query). The ret argument passed to the callback function will be an array containing various types of records. Each object has a property type that indicates the type of the current record. And depending on the type, additional properties will be present on the object:

              <omitted>

              Here is an example of the ret object passed to the callback:

              [ { type: 'A', address: '127.0.0.1', ttl: 299 },
                { type: 'CNAME', value: 'example.com' },
                { type: 'MX', exchange: 'alt4.aspmx.l.example.com', priority: 50 },
                { type: 'NS', value: 'ns1.example.com' },
                { type: 'TXT', entries: [ 'v=spf1 include:_spf.example.com ~all' ] },
                { type: 'SOA',
                  nsname: 'ns1.example.com',
                  hostmaster: 'admin.example.com',
                  serial: 156696742,
                  refresh: 900,
                  retry: 900,
                  expire: 1800,
                  minttl: 60 } ]
              

              DNS server operators may choose not to respond to ANY queries. It may be better to call individual methods like resolve4, resolveMx, and so on. For more details, see RFC 8482.

              namespace resolveAny

              • function resolveCaa(
                hostname: string,
                callback: (err: null | ErrnoException, records: CaaRecord[]) => void
                ): void;

                Uses the DNS protocol to resolve CAA records for the hostname. The addresses argument passed to the callback function will contain an array of certification authority authorization records available for the hostname (e.g. [{critical: 0, iodef: 'mailto:pki@example.com'}, {critical: 128, issue: 'pki.example.com'}]).

                namespace resolveCaa

                • function resolveCname(
                  hostname: string,
                  callback: (err: null | ErrnoException, addresses: string[]) => void
                  ): void;

                  Uses the DNS protocol to resolve CNAME records for the hostname. The addresses argument passed to the callback function will contain an array of canonical name records available for the hostname (e.g. ['bar.example.com']).

                  namespace resolveCname

                  • function resolveMx(
                    hostname: string,
                    callback: (err: null | ErrnoException, addresses: MxRecord[]) => void
                    ): void;

                    Uses the DNS protocol to resolve mail exchange records (MX records) for the hostname. The addresses argument passed to the callback function will contain an array of objects containing both a priority and exchange property (e.g. [{priority: 10, exchange: 'mx.example.com'}, ...]).

                    namespace resolveMx

                    • function resolveNaptr(
                      hostname: string,
                      callback: (err: null | ErrnoException, addresses: NaptrRecord[]) => void
                      ): void;

                      Uses the DNS protocol to resolve regular expression-based records (NAPTR records) for the hostname. The addresses argument passed to the callback function will contain an array of objects with the following properties:

                      • flags
                      • service
                      • regexp
                      • replacement
                      • order
                      • preference
                      {
                        flags: 's',
                        service: 'SIP+D2U',
                        regexp: '',
                        replacement: '_sip._udp.example.com',
                        order: 30,
                        preference: 100
                      }
                      

                      namespace resolveNaptr

                      • function resolveNs(
                        hostname: string,
                        callback: (err: null | ErrnoException, addresses: string[]) => void
                        ): void;

                        Uses the DNS protocol to resolve name server records (NS records) for the hostname. The addresses argument passed to the callback function will contain an array of name server records available for hostname (e.g. ['ns1.example.com', 'ns2.example.com']).

                        namespace resolveNs

                        • function resolvePtr(
                          hostname: string,
                          callback: (err: null | ErrnoException, addresses: 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.

                          namespace resolvePtr

                          • function resolveSoa(
                            hostname: string,
                            callback: (err: null | ErrnoException, address: SoaRecord) => void
                            ): void;

                            Uses the DNS protocol to resolve a start of authority record (SOA record) for the hostname. The address argument passed to the callback function will be an object with the following properties:

                            • nsname
                            • hostmaster
                            • serial
                            • refresh
                            • retry
                            • expire
                            • minttl
                            {
                              nsname: 'ns.example.com',
                              hostmaster: 'root.example.com',
                              serial: 2013101809,
                              refresh: 10000,
                              retry: 2400,
                              expire: 604800,
                              minttl: 3600
                            }
                            

                            namespace resolveSoa

                            • function resolveSrv(
                              hostname: string,
                              callback: (err: null | ErrnoException, addresses: SrvRecord[]) => void
                              ): void;

                              Uses the DNS protocol to resolve service records (SRV records) for the hostname. The addresses argument passed to the callback function will be an array of objects with the following properties:

                              • priority
                              • weight
                              • port
                              • name
                              {
                                priority: 10,
                                weight: 5,
                                port: 21223,
                                name: 'service.example.com'
                              }
                              

                              namespace resolveSrv

                              • function resolveTxt(
                                hostname: string,
                                callback: (err: null | ErrnoException, addresses: string[][]) => void
                                ): void;

                                Uses the DNS protocol to resolve text queries (TXT records) for the hostname. The records argument passed to the callback function is a two-dimensional 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, these could be either joined together or treated separately.

                                namespace resolveTxt

                                • interface AnyAaaaRecord

                                • interface AnyARecord

                                • interface AnyCnameRecord

                                • interface AnyMxRecord

                                • interface AnyNaptrRecord

                                • interface AnyNsRecord

                                • interface AnyPtrRecord

                                • interface AnySoaRecord

                                • interface AnySrvRecord

                                • interface AnyTxtRecord

                                • interface CaaRecord

                                • interface LookupAddress

                                  • address: string

                                    A string representation of an IPv4 or IPv6 address.

                                  • family: number

                                    4 or 6, denoting the family of address, or 0 if the address is not an IPv4 or IPv6 address. 0 is a likely indicator of a bug in the name resolution service used by the operating system.

                                • interface LookupAllOptions

                                  • all: true

                                    When true, the callback returns all resolved addresses in an array. Otherwise, returns a single address.

                                  • family?: number | 'IPv4' | 'IPv6'

                                    The record family. Must be 4, 6, or 0. For backward compatibility reasons, 'IPv4' and 'IPv6' are interpreted as 4 and 6 respectively. The value 0 indicates that either an IPv4 or IPv6 address is returned. If the value 0 is used with { all: true } (see below), both IPv4 and IPv6 addresses are returned.

                                  • hints?: number
                                  • order?: 'ipv4first' | 'ipv6first' | 'verbatim'

                                    When verbatim, the resolved addresses are return unsorted. When ipv4first, the resolved addresses are sorted by placing IPv4 addresses before IPv6 addresses. When ipv6first, the resolved addresses are sorted by placing IPv6 addresses before IPv4 addresses. Default value is configurable using setDefaultResultOrder or --dns-result-order.

                                • interface LookupOneOptions

                                  • all?: false

                                    When true, the callback returns all resolved addresses in an array. Otherwise, returns a single address.

                                  • family?: number | 'IPv4' | 'IPv6'

                                    The record family. Must be 4, 6, or 0. For backward compatibility reasons, 'IPv4' and 'IPv6' are interpreted as 4 and 6 respectively. The value 0 indicates that either an IPv4 or IPv6 address is returned. If the value 0 is used with { all: true } (see below), both IPv4 and IPv6 addresses are returned.

                                  • hints?: number
                                  • order?: 'ipv4first' | 'ipv6first' | 'verbatim'

                                    When verbatim, the resolved addresses are return unsorted. When ipv4first, the resolved addresses are sorted by placing IPv4 addresses before IPv6 addresses. When ipv6first, the resolved addresses are sorted by placing IPv6 addresses before IPv4 addresses. Default value is configurable using setDefaultResultOrder or --dns-result-order.

                                • interface LookupOptions

                                  • all?: boolean

                                    When true, the callback returns all resolved addresses in an array. Otherwise, returns a single address.

                                  • family?: number | 'IPv4' | 'IPv6'

                                    The record family. Must be 4, 6, or 0. For backward compatibility reasons, 'IPv4' and 'IPv6' are interpreted as 4 and 6 respectively. The value 0 indicates that either an IPv4 or IPv6 address is returned. If the value 0 is used with { all: true } (see below), both IPv4 and IPv6 addresses are returned.

                                  • hints?: number
                                  • order?: 'ipv4first' | 'ipv6first' | 'verbatim'

                                    When verbatim, the resolved addresses are return unsorted. When ipv4first, the resolved addresses are sorted by placing IPv4 addresses before IPv6 addresses. When ipv6first, the resolved addresses are sorted by placing IPv6 addresses before IPv4 addresses. Default value is configurable using setDefaultResultOrder or --dns-result-order.

                                • interface MxRecord

                                • interface NaptrRecord

                                • interface RecordWithTtl

                                • interface ResolveOptions

                                • interface ResolverOptions

                                  • timeout?: number

                                    Query timeout in milliseconds, or -1 to use the default timeout.

                                  • tries?: number

                                    The number of tries the resolver will try contacting each name server before giving up.

                                • interface ResolveWithTtlOptions

                                • interface SoaRecord

                                • interface SrvRecord