UNPKG

latenz

Version:

Measure response latency when requesting a web host.

31 lines (23 loc) 589 B
(() => { 'use strict'; const dns = require('dns'), Stopper = require('stopper'); class MeasureDNS { constructor() { this.stopper = new Stopper('dns'); } run(hostname) { return new Promise((done, fail) => { this.stopper.start(); dns.lookup(hostname, (err, data) => { this.stopper.stop(); if (err) { throw new Error('Lookup for host failed: ' + hostname); } done([{key: 'lookup', time: this.stopper.measure()}]); }); }); } } module.exports = MeasureDNS; })();