new DNS([options])

Examples

Import the client library

const {DNS} = require('@google-cloud/dns');
<caption>Create a client that uses <a
href="https://cloud.google.com/docs/authentication/production#providing_credentials_to_your_application">Application
Default Credentials (ADC)</a>:</caption> const dns = new DNS();
<caption>Create a client with <a
href="https://cloud.google.com/docs/authentication/production#obtaining_and_providing_service_account_credentials_manually">explicit
credentials</a>:</caption> const dns = new DNS({ projectId:
'your-project-id', keyFilename: '/path/to/keyfile.json'
});

include:samples/quickstart.js

region_tag:dns_quickstart
Full quickstart example:

Parameter

Name Type Optional Description

options

 

Yes

Configuration options.

See also

What is Cloud DNS?

Methods

createZone(name, config[, callback]) → Promise containing CreateZoneResponse

Create a managed zone.

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, (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((data) => {
  const zone = data[0];
  const apiResponse = data[1];
});

Parameters

Name Type Optional Description

name

string

 

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

config

CreateZoneRequest

 

Config to set for the zone.

callback

CreateZoneCallback

Yes

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 

getZones([query][, callback]) → Promise containing GetZonesResponse

Gets a list of managed zones for the project.

Example

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

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

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

Parameters

Name Type Optional Description

query

GetZonesRequest

Yes

Query object for listing zones.

callback

GetZonesCallback

Yes

Callback function.

See also

ManagedZones: list API Documentation

Returns

Promise containing GetZonesResponse 

getZonesStream([query]) → ReadableStream

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

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', () => {
    // 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();
  });

Parameter

Name Type Optional Description

query

GetZonesRequest

Yes

Query object for listing zones.

Returns

ReadableStream 

A readable stream that emits Zone instances.

zone(name) → Zone

Get a reference to a Zone.

Example

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

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

Parameter

Name Type Optional Description

name

string

 

The unique name of the zone.

See also
Zone
Throws

error 

If a zone name is not provided.

Returns

Zone