Constructor

Resource

new Resource(options)

Parameter

options

Optional

ClientConfig

Configuration options.

See also

What is the Cloud Resource Manager?

Examples

Import the client library

const {Resource} = require('@google-cloud/resource');
<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 resource = new Resource();
<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 resource = new Resource({ projectId:
'your-project-id', keyFilename: '/path/to/keyfile.json'
});

Full quickstart example:

// Imports the Google Cloud client library
const {Resource} = require('@google-cloud/resource');

// Your Google Cloud Platform project ID
const projectId = process.env.GCLOUD_PROJECT || 'YOUR_PROJECT_ID';

// Creates a client
const resource = new Resource({projectId});

// Lists current projects
const [projects] = await resource.getProjects();

console.log('Projects:');
projects.forEach(project => console.log(project.id));

Property

getProjectsStream

Get a list of Resource/project objects as a readable object stream.

Parameter

query

object

Configuration object. See Resource#getProjects for a complete list of options.

Returns

stream 

Example

const {Resource} = require('@google-cloud/resource');
const resource = new Resource();

resource.getProjectsStream()
  .on('error', console.error)
  .on('data', project => {
    // `project` is a `Project` object.
  })
  .on('end', () => {
    // All projects retrieved.
  });

//-
// If you anticipate many results, you can end a stream early to prevent
// unnecessary processing and API requests.
//-
resource.getProjectsStream()
  .on('data', function(project) {
    this.end();
  });

Methods

operation

operation(name)

Get a reference to an existing operation.

Parameter

name

string

The name of the operation.

Throws

Error 

If a name is not provided.

Example

const {Resource} = require('@google-cloud/resource');
const resource = new Resource();

const operation = resource.operation('68850831366825');

project

project(id) returns Project

Create a Project object. See Resource#createProject to create a project.

Parameter

id

string

The ID of the project (eg: grape-spaceship-123).

Throws

Error 

If an ID is not provided.

Returns

Project 

Example

const {Resource} = require('@google-cloud/resource');
const resource = new Resource();

const project = resource.project('grape-spaceship-123');