npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2026 – Pkg Stats / Ryan Hefner

js-powerdns

v0.2.2

Published

A PowerDNS js wrapper

Readme

PowerDNS API Javascript Wrapper

This is a Wrapper for the PowerDNS REST API.

Important NGINX

Given a Bug on PowerDNS, we are using NGINX to proxy the request to PowerDNS.

Following is an example configuration for NGINX:

upstream pdns {
   server localhost:8091;
}

server {
  listen  8081;
  server_name pdns;

  location / {
    proxy_set_header Host $http_host;
    proxy_pass http://pdns/;
    proxy_buffering off;
    proxy_read_timeout 300s;
    gzip off;
  }

  client_max_body_size 4G;
  keepalive_timeout 10;
}

Table of Contents

SOA Serial Update

The PowerDNS API can update the serial number for you automatically, but for this you must create the zone whit the options soa_edit_api: 'DEFAULT', like:

const jsPowerdns = require('js-powerdns');
const api = new jsPowerdns({ url: 'http://127.0.0.1:8081', token: 'otto' });
const zone_name = 'tempdomain.com.';
const soa = {
  "name": "tempdomain.com",
  "type": "SOA",
  "content": "ns1.tempdomain.com root.tempdomain.com 0 10800 3600 604800 3600",
  "disabled": false,
  "ttl": 86400,
  "priority": 0
};
const records = [ soa ];
const zone_data = {
  'name': zone_name,
  'soa_edit': 'DEFAULT', 'soa_edit_api': 'DEFAULT', // <== THIS IS THE SAUCE
  'kind': 'Master', nameservers: ['ns1.tempdomain.com'],
  'masters': []
};
api.createZoneWithRecords(zone_data, records, callback);

Info from:

Example

First, instantiate the wrapper.

const jsPowerdns = require('js-powerdns');
const api = new jsPowerdns({ url: 'http://127.0.0.1:8081', token: 'otto' });

var callback = function(err, data) {
  if (err) return console.log(err);
  console.log(data);
};

// Get all the Zones
api.getZones(callback);
// [Zone, Zone, Zone]

jsPowerdns.version();
// "0.0.1"

Using Templates

If you use to create Zones with same content you can use a Zone Template.

A Zone Template is just a JSON object and the variable {{=zone.name}} which will take the zone name.

For Example:

const zoneData = { name: 'example.com', template: zoneTemplate };
api.createZone(zoneData, callback);

And the zoneTemplate is:

const zoneTemplate = {
  zone_data: {
    kind: 'Master',
    nameservers: ['ns1.example.com', 'ns2.example.com'],
    soa_edit: 'DEFAULT',
    soa_edit_api: 'DEFAULT',
    masters: []
  },
  zone_records:
  [
    {
      name: '{{=zone.name}}', type: 'SOA', content: 'ns1.{{=zone.name}} root.{{=zone.name}} 0 10800 3600 604800 3600', disabled: false, ttl: 86400, priority: 0
    },
    {
      name: '{{=zone.name}}', type: 'NS', content: '1.1.1.1', disabled: false, ttl: 86400, priority: 0
    },
    {
      name: '{{=zone.name}}', type: 'NS', content: '1.1.1.2', disabled: false, ttl: 86400, priority: 0
    },
    {
      name: '{{=zone.name}}', type: 'MX', content: '10 1.1.1.3', disabled: false, ttl: 86400, priority: 5
    },
    {
      name: 'www.{{=zone.name}}', type: 'A', content: '1.1.1.1', disabled: false, ttl: 86400, priority: 5
    }
  ]
};

Install

node:

$ npm install js-powerdns

webpack:

TODO

Callback

You have to pass a callback to all the functions, that receives to params:

  1. error, if any
  2. data, if any

For this documentations callback will always be:

function(err, data) {
  if (err) return console.log(err);
  console.log(data);
};

Errors

If an error happens, the library return an Object:

Error {
  status: 401 // HTTP result Code,
  reason: 'Unauthorized' // Text error description
}

Common Functions

Get all Zones

api.getZones(callback);
// [Zone, Zone...]

Get a Zone

Important: you have to use the zone name with a . at the end of it. For example if the zone name is example.com, you must use example.com..

api.getZone("example.com.", callback);
// Zone {
//  url: '/servers/localhost/zones/example.com.',
//  id: 'example.com.',
//  name: 'example.com.',
//  dnssec: false,
//  account: '',
//  masters: [],
//  records: undefined,
// }

Create a Zone

const zone_object = { name: 'example.org', kind: 'Master', nameservers: [] };
api.createZone(zone_object, callback);
// Zone {}

Create a Zone with Records

// New Zone object
const zone_object = { name: 'example.org', kind: 'Master', nameservers: [] };

// New Records objects
const records = [];
const record1 = { "name": "record1.example.org", "content": "192.0.5.1",
                 "disabled": false, "ttl": 86400, "type": "A"
               };
const record2 = { "name": "record2.example.org", "content": "192.0.5.1",
                "disabled": false, "ttl": 86400, "type": "A"
              };
records.push(record1);
records.push(record2);

api.createZoneWithRecords(zone_data, records, callback);
// Zone {}

Delete Zone

api.deleteZone("example.com.", callback);
// {}

Delete Records

You need to use an object with name and content attributes to reference the Record.

// Record to delete
const record = { "name": "record1.example.org", "content": "192.0.5.1" }

// deleteRecords(zone_url, records_to_be_deleted, callback)
api.deleteRecords('/servers/localhost/zones/example.org.', record, callback)

// Zone {} with records deleted

If you have a Zone object you can use:

// Record to delete
const record = { "name": "record1.example.org", "content": "192.0.5.1" }

// zone is a Zone {}
zone.deleteRecords(record, callback);

Create or Modify Records

The function createOrModifyRecords update the Record information if there is a match for the content and name of the record object.

If no match, a new Record is created.

// Record to add
const record = { "name": "record1.example.org", "content": "192.0.5.1" }

// Add new Record
zone.createOrModifyRecords(record, callback);

record.content = '1.1.1.2';

// Modify Record
zone.createOrModifyRecords(record, callback);