DNS
Source: index.
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.
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
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 |
|
Config to set for the zone. |
|
|
callback |
Yes |
Callback function. |
- See also
- Zone#create
- Throws
-
errorIf a zone name is not provided.
-
errorIf a zone dnsName is not provided.
-
ErrorIf 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 |
Yes |
Query object for listing zones. |
|
|
callback |
Yes |
Callback function. |
- See also
- 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 |
Yes |
Query object for listing zones. |
- Returns
-
ReadableStreamA 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. |