Sign Up for Free

RunKit +

Try any Node.js package right in your browser

This is a playground to test code. It runs a full Node.js environment and already has all of npm’s 1,000,000+ packages pre-installed, including @cryptoscamdb/graceful-dns with all npm packages installed. Try it out:

var gracefulDns = require("@cryptoscamdb/graceful-dns")

This service is provided by RunKit and is not affiliated with npm, Inc or the package authors.

@cryptoscamdb/graceful-dns v1.1.0

An NPM package to provide non-rejecting promises for Node's DNS module

graceful-dns

Disclaimer

Are you writing code in dev environments? Check out the experimental DNS Promises API (added in v10.6.0)

Do you want promises to reject instead of returning undefined? Check out dns-then

This project wraps a part of Node.js's dns module in non-rejecting promises (instead of rejecting, it returns undefined. It also parses URLs to hostnames automatically. It's not a 1:1 port.

Usage

npm i -P @cryptoscamdb/graceful-dns

API

  • getServers() - returns an array of IP addresses which are configured for DNS lookups
  • setServers(servers) - configures an array of IP addresses which are configured for DNS lookups
  • getIP(hostname) - returns a promise which will resolve to either undefined or the IP address
  • getDNS(hostname) - returns a promise which will resolve to either undefined or an array of DNS records
  • getNS(hostname) - returns a promise which will resolve to either undefined or an array of nameservers
  • reverseDNS(ip) - returns a promise which will resolve to either undefined or an array of hostnames

Examples

import { getIP } from '@cryptoscamdb/graceful-dns';

getIP('example.com')
    .then((ip: string) => {
        if (ip) {
            console.log("Found IP:", ip);
        } else {
            console.log("Could not find IP address");
        }
    })
    .catch(() => {
        // This should never be called
    });
RunKit is a free, in-browser JavaScript dev environment for prototyping Node.js code, with every npm package installed. Sign up to share your code.
Sign Up for Free