@neferett/cloudflaredns
TypeScript icon, indicating that this package has built-in type declarations

1.0.5 • Public • Published

Cloudflare DNSRecord CRUD NodeJS

Downloads Version License

Installation

npm install @neferett/cloudflaredns

 Cloudflare.load({
     cloudflareToken: token,
 });

How to use

DNS Records:

Creating a new record cloudflare record with a Zone ID

DNSRecords.createRecord(
 zoneId, 
 {
     content: "127.0.0.1", name: "test.example.com", ttl: 120, type: EnumRecordType.A
 })
.then((record: IRecord) => ...);

Creating without ZoneID but only domain name

Zone.getZoneByDomainName('example.com').then((zone: IZone | undefined) => {
    if (zone === undefined) return;

    return DNSRecords.createRecord(
        zone.id, 
        {
            content: "127.0.0.1", name: "test.example.com", ttl: 120, type: EnumRecordType.A
        })
    .then((record: IRecord) => ...);
});

Same as Creating processus you can do the same with the following functions:

DNSRecords.updateRecord(
 zoneId, 
 {
     content: "127.0.0.2", name: "test.example.com", ttl: 120, type: EnumRecordType.A
 })
.then((record: IRecord) => ...);

// Delete method only takes id as parameter 
DNSRecords.deleteRecord(
    zoneId, {id: recordID}
    )
.then((record: IRecord) => ...);

You can read your records by Name or IDs using the following methods:

DNSRecords.getRecordByName(zoneId, 'test.example.com').then((record: IRecord | undefined) => ...)
DNSRecords.getRecordById(zoneId, '45678987654').then((record: IRecord | undefined) => ...)

You can read all your records:

DNSRecords.listRecords(zoneId).then((records:IRecord[]) => ...)

Zones:

To avoid you to always have Zone ID you can retrieve them dynamically:

Zone.getZoneByDomainName('example.com').then((zone: IZone | undefined) => ...)

You can also read them all:

Zone.listZones().then((zones: IZone[]) => ...)

Other Available Methods

// Getting all records linked to a zone
Zone.getLinkedRecords(recordId).then((record: IRecord[]) => ...)

// Dynamic action when using website form with string as method name
recordActionByIDs(action: 'updateRecord' | 'deleteRecord' | 'createRecord' , zoneId: string, record: IRecordBody | {id: string});

License

Licensed under MIT

Readme

Keywords

none

Package Sidebar

Install

npm i @neferett/cloudflaredns

Weekly Downloads

4

Version

1.0.5

License

ISC

Unpacked Size

19.7 kB

Total Files

27

Last publish

Collaborators

  • neferett