npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

dns.agent

v0.1.1

Published

DNS agent

Downloads

36

Readme

dns-agent

DNS agent

Table of contents

Links

Get Started

// The main entrance of package *dns-agent* is a class.
const DnsAgent = require('dns-agent');

// Create an instance.
const agent = new DnsAgent({
    // Time-To-Live of resolved address (in seconds).
    ttl: 86400,

    // Method to execute name resolving.
    // . "system"   means to use dns.lookup / getaddrinfo(3).
    // . "network"  means to perform a DNS query on the network.
    // . <IP>       DNS server to be used.
    // The default value is "system".
    source: 'system'
});

agent.lookup4('localhost', (err, ipv4) => {
    // ...
});

API

class DnsAgent

The main entrance of dns-agent is a class (named DnsAgent in following code snippets).

  • class DnsAgent(object options)
    The only argument may be passed to the constructor is an option object.

    const DnsAgent = require('dns-agent');
    const agent = new DnsAgent({ ttl, source });
    • ttl number DEFAULT 86400 (unit: seconds)
      Time-To-Live of resolved address.

    • source string DEFAULT "system"
      Acceptable values may be "system" | "network" | "<IP_address>".

      When source has a value of "system", dns-agent will use dns.lookup() to find the responding IP address of hostname. It is actually, according to Node.js Documentation, DNS, implemented as a synchronous call to getaddrinfo(3).

      When the value is "network", dns.resolve() will be used. That means to always perform a DNS query on the network. However, if there is some name resolving result not expired, whether or not it is stored in current instance of dns-agent, it will be returned whitout querying the DNS server.

      Else if "<IP_address>" set, dns-agent behaves like what it does on "network" but using the specified DNS server.

  • Promise | void agent.lookup4(string hostname [, Function callback ])
    Resolve the hostname into the first found A(IPV4) address. This is a PoC function that will return an instance of Promise if no callback passed, or return void and invoke the passed callback.

    • hostname string
    • callback(Error error, String ipv4) Function OPTIONAL

Examples

Why dns-agent

On designing another package htp, I think it maybe helpful for those developing with htp to be informed how many time an HTTP/HTTPs request spends on each step including (host)name resolving. So, I will try dns.lookup() before really launching the request. It works as expected in unit test. However, when hundreds of, even thousands of requests happen in very short time, repeatedly invoking of dns.lookup() may lead to unexpected exception. Maybe it is regarded as something like DoS attack by system or DNS server. So, I write dns-agent and delegate the actions on dns to it.

Honorable Dependents

Of course, htp is the first dependent.

About

For convenience, this package has following names (alias):