DNS

DNS

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.

Constructor

new DNS(optionsopt)

Parameters:
Name Type Attributes Description
options ClientConfig <optional>

Configuration options.

See:
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');

  // Creates a client
  const dns = new DNS();

  async function quickstart() {
    // Lists all zones in the current project
    const [zones] = await dns.getZones();
    console.log('Zones:');
    zones.forEach(zone => console.log(zone.name));
  }
  quickstart();

Methods

createZone(name, config, callbackopt) → {Promise.<CreateZoneResponse>}

Create a managed zone.

Parameters:
Name Type Attributes Description
name string

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

config CreateZoneRequest

Config to set for the zone.

callback CreateZoneCallback <optional>

Callback function.

See:
Throws:
  • If a zone name is not provided.

    Type
    error
  • If a zone dnsName is not provided.

    Type
    error
  • If a name is not provided.

    Type
    Error
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];
});

getZones(queryopt, callbackopt) → {Promise.<GetZonesResponse>}

Gets a list of managed zones for the project.

Parameters:
Name Type Attributes Description
query GetZonesRequest <optional>

Query object for listing zones.

callback GetZonesCallback <optional>

Callback function.

See:
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];
});

getZonesStream(queryopt) → {ReadableStream}

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

Parameters:
Name Type Attributes Description
query GetZonesRequest <optional>

Query object for listing zones.

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(name) → {Zone}

Get a reference to a Zone.

Parameters:
Name Type Description
name string

The unique name of the zone.

See:
Throws:

If a zone name is not provided.

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

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