title: npm module function interception. specifically base module 'dns'
body: <pre><code>import DNS from 'dns'
  
  DNS.resolveTxt('test-website.com', (err, addresses) =&gt; {
        console.log(err, addresses);
  })
  </code></pre>
  <p>Above would be an example usage of how the node resolves a web address. I want to build a nock library for 'dns', and intercept the handler. (This would be used in the AWS nock library I've created for Route53, so this is not for &quot;testing&quot; purposes). I'm seeing some rewiremock stuff that makes sense, but that seems like a testing mocking tool. Is there anyway to achieve this interception? Rather than just intercepting it in between and moving over to the original method, I want to figure out how to replace the whole handler itself. *</p>
  <p>Clarification: I want to use DNS.resolveTxt directly and the <code>addresses</code> I get from the response will be my custom.</p>
  <p>Clarification #2: I want to ideally nock the whole DNS library. resolveTxt is just an example.</p>
  <p>Clarification #3: I want do mock the DNS globally across my service. Not just for a single use.</p>
  <p>Clarification #4 (important): I think my question is how I can intercept the tcp requests to the DNS. <code>sudo tcpdump host 1.1.1.1</code> shows the current calls to the DNS server set from my computer. If I were to dns.setServer('1.2.3.4') for example, and do a <code>sudo tcpdump host 1.2.3.4</code>, every time I call <code>DNS.resolveTxt</code>, I am able to see the call logs. Any idea how to intercept that?</p>