@google-cloud/compute

v4.7.0
Google Compute Engine Client Library for Node.js
google apis client google api client google apis google api google google cloud platform google cloud cloud google compute and 80 more...

Google Cloud Platform logo

Google Compute Engine: Node.js Client

release level npm version

Google Compute Engine Client Library for Node.js

A comprehensive list of changes in each version may be found in the CHANGELOG.

Read more about the client libraries for Cloud APIs, including the older Google APIs Client Libraries, in Client Libraries Explained.

Table of contents:

Quickstart

Before you begin

  1. [Select or create a Cloud Platform project][projects].
  2. [Enable billing for your project][billing].
  3. [Enable the Google Compute Engine API][enable_api].
  4. [Set up authentication with a service account][auth] so you can access the API from your local workstation.

Installing the client library

npm install @google-cloud/compute

Using the client library

/**
 * TODO(developer): Uncomment and replace these variables before running the sample.
 */
// const projectId = 'YOUR_PROJECT_ID';

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

// List all instances in the specified project.
async function listAllInstances() {
  const instancesClient = new compute.InstancesClient();

  //Use the `maxResults` parameter to limit the number of results that the API returns per response page.
  const aggListRequest = instancesClient.aggregatedListAsync({
    project: projectId,
    maxResults: 5,
  });

  console.log('Instances found:');

  // Despite using the `maxResults` parameter, you don't need to handle the pagination
  // yourself. The returned object handles pagination automatically,
  // requesting next pages as you iterate over the results.
  for await (const [zone, instancesObject] of aggListRequest) {
    const instances = instancesObject.instances;

    if (instances && instances.length > 0) {
      console.log(` ${zone}`);
      for (const instance of instances) {
        console.log(` - ${instance.name} (${instance.machineType})`);
      }
    }
  }
}

listAllInstances();

Samples

Samples are in the samples/ directory. Each sample's README.md has instructions for running its sample.

Sample Source Code Try it
Accelerator_types.aggregated_list source code ![Open in Cloud Shell][shell_img]
Accelerator_types.get source code ![Open in Cloud Shell][shell_img]
Accelerator_types.list source code ![Open in Cloud Shell][shell_img]
Addresses.aggregated_list source code ![Open in Cloud Shell][shell_img]
Addresses.delete source code ![Open in Cloud Shell][shell_img]
Addresses.get source code ![Open in Cloud Shell][shell_img]
Addresses.insert source code ![Open in Cloud Shell][shell_img]
Addresses.list source code ![Open in Cloud Shell][shell_img]
Addresses.move source code ![Open in Cloud Shell][shell_img]
Addresses.set_labels source code ![Open in Cloud Shell][shell_img]
Autoscalers.aggregated_list source code ![Open in Cloud Shell][shell_img]
Autoscalers.delete source code ![Open in Cloud Shell][shell_img]
Autoscalers.get source code ![Open in Cloud Shell][shell_img]
Autoscalers.insert source code ![Open in Cloud Shell][shell_img]
Autoscalers.list source code ![Open in Cloud Shell][shell_img]
Autoscalers.patch source code ![Open in Cloud Shell][shell_img]
Autoscalers.update source code ![Open in Cloud Shell][shell_img]
Backend_buckets.add_signed_url_key source code ![Open in Cloud Shell][shell_img]
Backend_buckets.delete source code ![Open in Cloud Shell][shell_img]
Backend_buckets.delete_signed_url_key source code ![Open in Cloud Shell][shell_img]
Backend_buckets.get source code ![Open in Cloud Shell][shell_img]
Backend_buckets.get_iam_policy source code ![Open in Cloud Shell][shell_img]
Backend_buckets.insert source code ![Open in Cloud Shell][shell_img]
Backend_buckets.list source code ![Open in Cloud Shell][shell_img]
Backend_buckets.patch source code ![Open in Cloud Shell][shell_img]
Backend_buckets.set_edge_security_policy source code ![Open in Cloud Shell][shell_img]
Backend_buckets.set_iam_policy source code ![Open in Cloud Shell][shell_img]
Backend_buckets.test_iam_permissions source code ![Open in Cloud Shell][shell_img]
Backend_buckets.update source code ![Open in Cloud Shell][shell_img]
Backend_services.add_signed_url_key source code ![Open in Cloud Shell][shell_img]
Backend_services.aggregated_list source code ![Open in Cloud Shell][shell_img]
Backend_services.delete source code ![Open in Cloud Shell][shell_img]
Backend_services.delete_signed_url_key source code ![Open in Cloud Shell][shell_img]
Backend_services.get source code ![Open in Cloud Shell][shell_img]
Backend_services.get_health source code ![Open in Cloud Shell][shell_img]
Backend_services.get_iam_policy source code ![Open in Cloud Shell][shell_img]
Backend_services.insert source code ![Open in Cloud Shell][shell_img]
Backend_services.list source code ![Open in Cloud Shell][shell_img]
Backend_services.list_usable source code ![Open in Cloud Shell][shell_img]
Backend_services.patch source code ![Open in Cloud Shell][shell_img]
Backend_services.set_edge_security_policy source code ![Open in Cloud Shell][shell_img]
Backend_services.set_iam_policy source code ![Open in Cloud Shell][shell_img]
Backend_services.set_security_policy source code ![Open in Cloud Shell][shell_img]
Backend_services.test_iam_permissions source code ![Open in Cloud Shell][shell_img]
Backend_services.update source code ![Open in Cloud Shell][shell_img]
Disk_types.aggregated_list source code ![Open in Cloud Shell][shell_img]
Disk_types.get source code ![Open in Cloud Shell][shell_img]
Disk_types.list source code ![Open in Cloud Shell][shell_img]
Disks.add_resource_policies source code ![Open in Cloud Shell][shell_img]
Disks.aggregated_list source code ![Open in Cloud Shell][shell_img]
Disks.bulk_insert source code ![Open in Cloud Shell][shell_img]
Disks.create_snapshot source code ![Open in Cloud Shell][shell_img]
Disks.delete source code ![Open in Cloud Shell][shell_img]
Disks.get source code ![Open in Cloud Shell][shell_img]
Disks.get_iam_policy source code ![Open in Cloud Shell][shell_img]
Disks.insert source code ![Open in Cloud Shell][shell_img]
Disks.list source code ![Open in Cloud Shell][shell_img]
Disks.remove_resource_policies source code ![Open in Cloud Shell][shell_img]
Disks.resize source code ![Open in Cloud Shell][shell_img]
Disks.set_iam_policy source code ![Open in Cloud Shell][shell_img]
Disks.set_labels source code ![Open in Cloud Shell][shell_img]
Disks.start_async_replication source code ![Open in Cloud Shell][shell_img]
Disks.stop_async_replication source code ![Open in Cloud Shell][shell_img]
Disks.stop_group_async_replication source code ![Open in Cloud Shell][shell_img]
Disks.test_iam_permissions source code ![Open in Cloud Shell][shell_img]
Disks.update source code ![Open in Cloud Shell][shell_img]
External_vpn_gateways.delete source code ![Open in Cloud Shell][shell_img]
External_vpn_gateways.get source code ![Open in Cloud Shell][shell_img]
External_vpn_gateways.insert source code ![Open in Cloud Shell][shell_img]
External_vpn_gateways.list source code ![Open in Cloud Shell][shell_img]
External_vpn_gateways.set_labels source code ![Open in Cloud Shell][shell_img]
External_vpn_gateways.test_iam_permissions source code ![Open in Cloud Shell][shell_img]
Firewall_policies.add_association source code ![Open in Cloud Shell][shell_img]
Firewall_policies.add_rule source code ![Open in Cloud Shell][shell_img]
Firewall_policies.clone_rules source code ![Open in Cloud Shell][shell_img]
Firewall_policies.delete source code ![Open in Cloud Shell][shell_img]
Firewall_policies.get source code ![Open in Cloud Shell][shell_img]
Firewall_policies.get_association source code ![Open in Cloud Shell][shell_img]
Firewall_policies.get_iam_policy source code ![Open in Cloud Shell][shell_img]
Firewall_policies.get_rule source code ![Open in Cloud Shell][shell_img]
Firewall_policies.insert source code ![Open in Cloud Shell][shell_img]
Firewall_policies.list source code ![Open in Cloud Shell][shell_img]
Firewall_policies.list_associations source code ![Open in Cloud Shell][shell_img]
Firewall_policies.move source code ![Open in Cloud Shell][shell_img]
Firewall_policies.patch source code ![Open in Cloud Shell][shell_img]
Firewall_policies.patch_rule source code ![Open in Cloud Shell][shell_img]
Firewall_policies.remove_association source code ![Open in Cloud Shell][shell_img]
Firewall_policies.remove_rule source code ![Open in Cloud Shell][shell_img]
Firewall_policies.set_iam_policy source code ![Open in Cloud Shell][shell_img]
Firewall_policies.test_iam_permissions source code ![Open in Cloud Shell][shell_img]
Firewalls.delete source code ![Open in Cloud Shell][shell_img]
Firewalls.get source code ![Open in Cloud Shell][shell_img]
Firewalls.insert source code ![Open in Cloud Shell][shell_img]
Firewalls.list source code ![Open in Cloud Shell][shell_img]
Firewalls.patch source code ![Open in Cloud Shell][shell_img]
Firewalls.update source code ![Open in Cloud Shell][shell_img]
Forwarding_rules.aggregated_list source code ![Open in Cloud Shell][shell_img]
Forwarding_rules.delete source code ![Open in Cloud Shell][shell_img]
Forwarding_rules.get source code ![Open in Cloud Shell][shell_img]
Forwarding_rules.insert source code ![Open in Cloud Shell][shell_img]
Forwarding_rules.list source code ![Open in Cloud Shell][shell_img]
Forwarding_rules.patch source code ![Open in Cloud Shell][shell_img]
Forwarding_rules.set_labels source code ![Open in Cloud Shell][shell_img]
Forwarding_rules.set_target source code ![Open in Cloud Shell][shell_img]
Global_addresses.delete source code ![Open in Cloud Shell][shell_img]
Global_addresses.get source code ![Open in Cloud Shell][shell_img]
Global_addresses.insert source code ![Open in Cloud Shell][shell_img]
Global_addresses.list source code ![Open in Cloud Shell][shell_img]
Global_addresses.move source code ![Open in Cloud Shell][shell_img]
Global_addresses.set_labels source code ![Open in Cloud Shell][shell_img]
Global_forwarding_rules.delete source code ![Open in Cloud Shell][shell_img]
Global_forwarding_rules.get source code ![Open in Cloud Shell][shell_img]
Global_forwarding_rules.insert source code ![Open in Cloud Shell][shell_img]
Global_forwarding_rules.list source code ![Open in Cloud Shell][shell_img]
Global_forwarding_rules.patch source code ![Open in Cloud Shell][shell_img]
Global_forwarding_rules.set_labels source code ![Open in Cloud Shell][shell_img]
Global_forwarding_rules.set_target source code ![Open in Cloud Shell][shell_img]
Global_network_endpoint_groups.attach_network_endpoints source code ![Open in Cloud Shell][shell_img]
Global_network_endpoint_groups.delete source code ![Open in Cloud Shell][shell_img]
Global_network_endpoint_groups.detach_network_endpoints source code ![Open in Cloud Shell][shell_img]
Global_network_endpoint_groups.get source code ![Open in Cloud Shell][shell_img]
Global_network_endpoint_groups.insert source code ![Open in Cloud Shell][shell_img]
Global_network_endpoint_groups.list source code ![Open in Cloud Shell][shell_img]
Global_network_endpoint_groups.list_network_endpoints source code ![Open in Cloud Shell][shell_img]
Global_operations.aggregated_list source code ![Open in Cloud Shell][shell_img]
Global_operations.delete source code ![Open in Cloud Shell][shell_img]
Global_operations.get source code [![Open in Cloud Shell][shell_img]](https://console.cloud.google.com/cloudshell/open?git_repo=https://github.com/googleapis/google-cloud-node&page=editor&open_in_editor=packages/google-cloud-compute/samples/generated/v1/global_operations.get.js,packages/google-cloud-
npm i @google-cloud/compute

Metadata

Downloads

Maintainers