5.0 KiB
@push.rocks/smartdns
smart dns methods written in TypeScript
Install
To install @push.rocks/smartdns
, use the following command with npm:
npm install @push.rocks/smartdns --save
Or with yarn
:
yarn add @push.rocks/smartdns
Make sure you have a TypeScript environment setup to utilize the library effectively.
Usage
@push.rocks/smartdns
is a comprehensive library aimed at facilitating smart DNS operations, leveraging TypeScript for enhanced development experience. This section aims to cover several real-world scenarios demonstrating the library's capabilities, from basic DNS lookups to more advanced DNS management tasks.
Getting Started
First, ensure you import the module into your TypeScript project:
import { Smartdns } from '@push.rocks/smartdns';
Basic DNS Record Lookup
Often, the need arises to fetch various DNS records for a domain. @push.rocks/smartdns
simplifies this by providing intuitive methods.
Fetching A Records
To fetch an "A" record for a domain:
const dnsManager = new Smartdns({});
const aRecords = await dnsManager.getRecordsA('example.com');
console.log(aRecords);
Fetching AAAA Records
Similarly, for "AAAA" records:
const aaaaRecords = await dnsManager.getRecordsAAAA('example.com');
console.log(aaaaRecords);
Advanced DNS Management
Beyond simple queries, @push.rocks/smartdns
offers functionalities suitable for more complex DNS management scenarios.
Checking DNS Propagation
When changing DNS records, ensuring that the new records have propagated fully is crucial. @push.rocks/smartdns
facilitates this with a method to check a DNS record until it is available globally.
const recordType = 'TXT'; // Record type: A, AAAA, CNAME, TXT etc.
const expectedValue = 'your_expected_value';
const isAvailable = await dnsManager.checkUntilAvailable('example.com', recordType, expectedValue);
if (isAvailable) {
console.log('Record propagated successfully.');
} else {
console.log('Record propagation failed or timed out.');
}
Leveraging DNS for Application Logic
DNS records can serve beyond mere domain-to-IP resolution; they can be instrumental in application logic, such as feature flagging or environment-specific configurations.
Example: Feature Flagging via TXT Records
Consider leveraging TXT records for enabling/disabling features dynamically without deploying new code.
const txtRecords = await dnsManager.getRecordsTxt('features.example.com');
const featureFlags = txtRecords.reduce((acc, record) => {
const [flag, isEnabled] = record.value.split('=');
acc[flag] = isEnabled === 'true';
return acc;
}, {});
if (featureFlags['NewFeature']) {
// Logic to enable the new feature
}
Conclusion
@push.rocks/smartdns
offers a versatile set of tools for DNS querying and management, tailored for applications at any scale. The examples provided illustrate the library's potential use cases, highlighting its applicability in various scenarios from basic lookups to facilitating complex application features through DNS.
For the full spectrum of functionalities, including detailed method documentation and additional use cases, consult the module's TypeDoc documentation. This will serve as a comprehensive guide to leveraging @push.rocks/smartdns
effectively in your projects.
Remember, DNS changes might take time to propagate worldwide, and the utility methods provided by @push.rocks/smartdns
for checking record availability will be invaluable in managing these changes seamlessly.
License and Legal Information
This repository contains open-source code that is licensed under the MIT License. A copy of the MIT License can be found in the license file within this repository.
Please note: The MIT License does not grant permission to use the trade names, trademarks, service marks, or product names of the project, except as required for reasonable and customary use in describing the origin of the work and reproducing the content of the NOTICE file.
Trademarks
This project is owned and maintained by Task Venture Capital GmbH. The names and logos associated with Task Venture Capital GmbH and any related products or services are trademarks of Task Venture Capital GmbH and are not included within the scope of the MIT license granted herein. Use of these trademarks must comply with Task Venture Capital GmbH's Trademark Guidelines, and any usage must be approved in writing by Task Venture Capital GmbH.
Company Information
Task Venture Capital GmbH
Registered at District court Bremen HRB 35230 HB, Germany
For any legal inquiries or if you require further information, please contact us via email at hello@task.vc.
By using this repository, you acknowledge that you have read this section, agree to comply with its terms, and understand that the licensing of the code does not imply endorsement by Task Venture Capital GmbH of any derivative works.