Constructor

DNS

new DNS(options)

Cloud DNS is a high- performance, resilient, global DNS service that provides a cost-effective way to make your applications and services available to your users. This programmable, authoritative DNS service can be used to easily publish and manage DNS records using the same infrastructure relied upon by Google.

Parameter

options

Optional

ClientConfig

Configuration options.

See also

What is Cloud DNS?

Examples

Import the client library

const DNS = require('@google-cloud/dns');

Create a client that uses Application Default Credentials (ADC):

const dns = new DNS();

Create a client with explicit credentials:

const dns = new DNS({
  projectId: 'your-project-id',
  keyFilename: '/path/to/keyfile.json'
});

Full quickstart example:

// Imports the Google Cloud client library
const DNS = require('@google-cloud/dns');

// Your Google Cloud Platform project ID
const projectId = 'YOUR_PROJECT_ID';

// Creates a client
const dns = new DNS({
  projectId: projectId,
});

// Lists all zones in the current project
dns
  .getZones()
  .then(results => {
    const zones = results[0];

    console.log('Zones:');
    zones.forEach(zone => console.log(zone.name));
  })
  .catch(err => {
    console.error('ERROR:', err);
  });

Property

Zone

static

Constructor

Zone class.

See also
Zone

Methods

createZone

createZone(name, config, callback) returns Promise containing CreateZoneResponse

Create a managed zone.

Parameter

name

string

Name of the zone to create, e.g. "my-zone".

config

Optional

CreateZoneRequest

Config to set for the zone.

callback

Optional

CreateZoneCallback

Callback function.

See also

ManagedZones: create API Documentation

Zone#create
Throws

error 

If a zone name is not provided.

error 

If a zone dnsName is not provided.

Error 

If a name is not provided.

Returns

Promise containing CreateZoneResponse 

Example

const DNS = require('@google-cloud/dns');
const dns = new DNS();

const config = {
  dnsName: 'example.com.', // note the period at the end of the domain.
  description: 'This zone is awesome!'
};

dns.createZone('my-awesome-zone', config, function(err, zone, apiResponse) {
  if (!err) {
    // The zone was created successfully.
  }
});

//-
// If the callback is omitted, we'll return a Promise.
//-
dns.createZone('my-awesome-zone', config).then(function(data) {
  const zone = data[0];
  const apiResponse = data[1];
});

getZones

getZones(query, callback) returns Promise containing GetZonesResponse

Gets a list of managed zones for the project.

Parameter

query

Optional

GetZonesRequest

Query object for listing zones.

callback

Optional

GetZonesCallback

Callback function.

See also

ManagedZones: list API Documentation

Returns

Promise containing GetZonesResponse 

Example

const DNS = require('@google-cloud/dns');
const dns = new DNS();

dns.getZones(function(err, zones, apiResponse) {});

//-
// If the callback is omitted, we'll return a Promise.
//-
dns.getZones().then(function(data) {
  const zones = data[0];
});

getZonesStream

getZonesStream(query) returns ReadableStream

Get Zone objects for all of the zones in your project as a readable object stream.

Parameter

query

Optional

GetZonesRequest

Query object for listing zones.

Returns

ReadableStream 

A readable stream that emits Zone instances.

Example

const DNS = require('@google-cloud/dns');
const dns = new DNS();

dns.getZonesStream()
  .on('error', console.error)
  .on('data', function(zone) {
    // zone is a Zone object.
  })
  .on('end', function() {
    // All zones retrieved.
  });

//-
// If you anticipate many results, you can end a stream early to prevent
// unnecessary processing and API requests.
//-
dns.getZonesStream()
  .on('data', function(zone) {
    this.end();
  });

zone

zone(name) returns Zone

Get a reference to a Zone.

Parameter

name

string

The unique name of the zone.

See also
Zone
Throws

error 

If a zone name is not provided.

Returns

Zone 

Example

const DNS = require('@google-cloud/dns');
const dns = new DNS();

const zone = dns.zone('my-zone');