UNPKG

dns2

Version:

A DNS Server and Client Implementation in Pure JavaScript with no dependencies.

28 lines (23 loc) 630 B
const https = require('https'); const get = url => new Promise(resolve => https.get(url, resolve)); const readStream = stream => { const buffer = []; return new Promise((resolve, reject) => { stream .on('error', reject) .on('data', chunk => { buffer.push(chunk); }) .on('end', () => resolve(Buffer.concat(buffer))); }); }; const GoogleClient = () => (name, type = 'ANY') => { return Promise .resolve() .then(() => get(`https://dns.google.com/resolve?name=${name}&type=${type}`)) .then(readStream) .then(JSON.parse); }; module.exports = GoogleClient;