Google Cloud Platform logo

Google Cloud Dataproc: Node.js Client

release level npm version codecov

Node.js idiomatic client for Cloud Dataproc .

Client API Reference

Quickstart

Before you begin

  1. Select or create a Cloud Platform project.

    Go to the projects page

  2. Enable billing for your project.

    Enable billing

  3. Enable the Google Cloud Dataproc API.

    Enable the API

  4. Set up authentication with a service account so you can access the API from your local workstation.

Installing the client library

npm install --save @google-cloud/dataproc

Using the client library

if (
  !process.env.GCLOUD_PROJECT ||
  !process.env.GOOGLE_APPLICATION_CREDENTIALS
) {
  throw new Error(
    'Usage: GCLOUD_PROJECT=<project_id> GOOGLE_APPLICATION_CREDENTIALS=<path to json key> node #{$0}'
  );
}

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

const client = new dataproc.v1.ClusterControllerClient({
  // optional auth parameters.
});

const projectId = process.env.GCLOUD_PROJECT;

// Iterate over all elements.
const region = 'global';
const request = {
  projectId: projectId,
  region: region,
};

client.listClusters(request).then(responses => {
  const resources = responses[0];
  console.log('Total resources:', resources.length);
  for (let i = 0; i < resources.length; i += 1) {
    console.log(resources[i]);
  }
});

// Or obtain the paged response.
const options = {autoPaginate: false};
const callback = responses => {
  // The actual resources in a response.
  const resources = responses[0];
  // The next request if the response shows that there are more responses.
  const nextRequest = responses[1];
  // The actual response object, if necessary.
  // const rawResponse = responses[2];
  for (let i = 0; i < resources.length; i += 1) {
    console.log(resources[i]);
  }
  if (nextRequest) {
    // Fetch the next page.
    return client.listClusters(nextRequest, options).then(callback);
  }
};
client.listClusters(request, options).then(callback);

client.listClustersStream(request).on('data', element => {
  console.log(element);
});

The Cloud Dataproc Node.js Client API Reference documentation also contains samples.

Versioning

This library follows Semantic Versioning .

This library is considered to be in alpha . This means it is still a work-in-progress and under active development. Any release is subject to backwards-incompatible changes at any time.

More Information: Google Cloud Platform Launch Stages

Contributing

Contributions welcome! See the Contributing Guide .

License

Apache Version 2.0

See LICENSE