Constructor

Project

new Project(resource, id)

A Project object allows you to interact with a Google Cloud Platform project.

Parameter

resource

Resource

Resource object this project belongs to.

id

string

The project's ID.

See also

Projects Overview

Project Resource

Example

const Resource = require('@google-cloud/resource');
const resource = new Resource();
const project = resource.project('grape-spaceship-123');

Property

id

string

Methods

create

create(config)

Create a project.

Parameter

config

Optional

object

See Resource#createProject.

Example

const Resource = require('@google-cloud/resource');
const resource = new Resource();
const project = resource.project('grape-spaceship-123');

project.create(function(err, project, operation, apiResponse) {
  if (err) {
    // Error handling omitted.
  }

  // `operation` will emit `error` or `complete` when the status updates.

  operation
    .on('error', function(err) {})
    .on('complete', function() {
      // Project was created successfully!
    });
});

//-
// If the callback is omitted, we'll return a Promise.
//-
project.create()
  .then(function(data) {
    const project = data[0];
    const operation = data[1];
    const apiResponse = data[2];

    return operation.promise();
  })
  .then(function(data) {
    const operationMetadata = data[0];

    // Project created successfully!
  });

delete

delete(callback)

Delete the project.

This method only works if you are authenticated as yourself, e.g. using the gcloud SDK.

Parameter

callback

Optional

function()

The callback function.

Values in callback have the following properties:

Parameter

err

error

An error returned while making this request.

Value may be null.

apiResponse

object

The full API response.

See also

projects: delete API Documentation

Example

const Resource = require('@google-cloud/resource');
const resource = new Resource();
const project = resource.project('grape-spaceship-123');

project.delete(function(err, apiResponse) {
  if (!err) {
    // The project was deleted!
  }
});

//-
// If the callback is omitted, we'll return a Promise.
//-
project.delete().then(function(data) {
  const apiResponse = data[0];
});

get

get(options)

Get a project if it exists.

You may optionally use this to "get or create" an object by providing an object with autoCreate set to true. Any extra configuration that is normally required for the create method must be contained within this object as well.

Parameter

options

Optional

options

Configuration object.

Values in options have the following properties:

Parameter

autoCreate

Optional

boolean

Automatically create the object if it does not exist.

Example

const Resource = require('@google-cloud/resource');
const resource = new Resource();
const project = resource.project('grape-spaceship-123');

project.get(function(err, project, apiResponse) {
  // `project.metadata` has been populated.
});

//-
// If the callback is omitted, we'll return a Promise.
//-
project.get().then(function(data) {
  const project = data[0];
  const apiResponse = data[1];
});

getMetadata

getMetadata(callback)

Get the metadata for the project.

Parameter

callback

Optional

function()

The callback function.

Values in callback have the following properties:

Parameter

err

error

An error returned while making this request.

Value may be null.

metadata

object

Metadata of the project from the API.

Value may be null.

apiResponse

object

Raw API response.

See also

projects: get API Documentation

Example

const Resource = require('@google-cloud/resource');
const resource = new Resource();
const project = resource.project('grape-spaceship-123');

project.getMetadata(function(err, metadata, apiResponse) {});

//-
// If the callback is omitted, we'll return a Promise.
//-
project.getMetadata().then(function(data) {
  const metadata = data[0];
  const apiResponse = data[1];
});

restore

restore(callback)

Restore a project.

This method only works if you are authenticated as yourself, e.g. using the gcloud SDK.

Parameter

callback

Optional

function()

The callback function.

Values in callback have the following properties:

Parameter

err

error

An error returned while making this request.

Value may be null.

apiResponse

object

Raw API response.

See also

projects: undelete API Documentation

Example

const Resource = require('@google-cloud/resource');
const resource = new Resource();
const project = resource.project('grape-spaceship-123');

project.restore(function(err, apiResponse) {
  if (!err) {
    // Project restored.
  }
});

//-
// If the callback is omitted, we'll return a Promise.
//-
project.restore().then(function(data) {
  const apiResponse = data[0];
});

setMetadata

setMetadata(metadata, callback)

Set the project's metadata.

This method only works if you are authenticated as yourself, e.g. using the gcloud SDK.

Parameter

metadata

object

See a Project resource.

callback

Optional

function()

The callback function.

Values in callback have the following properties:

Parameter

err

error

An error returned while making this request.

Value may be null.

apiResponse

object

The full API response.

See also

projects: update API Documentation

Project Resource

Example

const Resource = require('@google-cloud/resource');
const resource = new Resource();
const project = resource.project('grape-spaceship-123');

const metadata = {
  name: 'New name'
};

project.setMetadata(metadata, function(err, apiResponse) {
  if (!err) {
    // The project has been successfully updated.
  }
});

//-
// If the callback is omitted, we'll return a Promise.
//-
project.setMetadata(metadata).then(function(data) {
  const apiResponse = data[0];
});