@nasriya/dns
v1.0.6
Published
A DNS manager for your domains
Downloads
11
Readme
NasriyaDNS.
Visit us at www.nasriya.net.
NasriyaDNS is a DNS manager for your domains.
Made with ❤️ in Palestine 🇵🇸
[!IMPORTANT] 🌟 Support Our Open-Source Development! 🌟 We need your support to keep our projects going! If you find our > work valuable, please consider contributing. Your support helps us > continue to develop and maintain these tools.
Every contribution, big or small, makes a difference. Thank you for > your generosity and support!
If your server is running behind a dynamic IP address you can make use of Nasriya DNS manager to update the DNS records of your domain.
Notes:
- NasriyaDNS is part of HyperCloud's HTTP2 server framework.
Quick Start Guide
Installation
npm i @nasriya/dns
Importing
Import in ES6 modules
import hyperCloudDNS from '@nasriya/dns';
Import in CommonJS (CJS)
const hyperCloudDNS = require('@nasriya/dns').default;
Usage
Start by getting the new IP address:
// Get the machine's public IP
const public_ip: string = await hyperCloudDNS.helpers.getPublicIP();
DuckDNS
// Initialize a provider:
const duckdns: DuckDNSManager = hyperCloudDNS.duckdns(process.env.DUCKDNS_API_TOKEN);
// Update the IP address
await duckdns.records.update('<myDomain>', public_ip);
Cloudflare
import hyperCloudDNS from "nasriya-dns";
const cloudflare = hyperCloudDNS.cloudflare(process.env.CLOUDFLARE_API_TOKEN);
// If you know the Zone ID of your domain, uncomment the below line
// const zone_id = process.env.CLOUDFLARE_ZONE_ID;
// If you don't know the Zone ID. Comment the following 4 lines if you do
const zone_id: string = await cloudflare.zone.list({
accountName: '<domain.com>',
just_ids: true
}).then(list => list[0]) as string;
// Get all A records:
const records = await cloudflare.records.list(zone_id, {
type: 'A',
simplified: true
})
// Prepare the promises
const promises = records.map(record => {
return new Promise((resolve, reject) => {
cloudflare.records.update({
zone_id,
record,
record_id: record.id,
}).then(res => resolve(res)).catch(err => reject(err));
})
})
// Invoke promises
await Promise.allSettled(promises).then(res => {
const fulfilled = (res.filter(i => i.status === 'fulfilled') as unknown as PromiseFulfilledResult<unknown>[]).map(i => i.value);
const rejected = (res.filter(i => i.status === 'rejected') as unknown as PromiseRejectedResult[]).map(i => i.reason);
if (fulfilled.length === res.length) {
return Promise.resolve({ status: 'success', result: fulfilled });
} else {
return Promise.resolve({ status: 'failed', result: rejected });
}
})
License
Please read the license from here.