Constructor

DNS

new DNS(options)

Parameter

options

Optional

ClientConfig

Configuration options.

See also

What is Cloud DNS?

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'
});

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);
  });

Methods

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