Skip to content

silvolu/gcloud-node

Repository files navigation

Google Cloud Node.js Client

Node.js idiomatic client for Google Cloud Platform services.

NPM Version Travis Build Status Coverage Status

This client supports the following Google Cloud Platform services:

If you need support for other Google APIs, check out the Google Node.js API Client library.

Quick Start

$ npm install --save gcloud

Examples

Authorization

On Google Compute Engine

If you are running this client on Google Compute Engine, we handle authorization for you with no configuration. You just need to make sure that when you set up the GCE instance, you add the correct scopes for the APIs you want to access.

Elsewhere

If you are not running this client on Google Compute Engine, you need a Google Developers service account. To create a service account:

  1. Visit the Google Developers Console.
  2. Create a new project or click on an existing project.
  3. Navigate to APIs & auth > APIs section and turn on the following APIs (you may need to enable billing in order to use these services):
  • Google Cloud Datastore API
  • Google Cloud Storage
  • Google Cloud Storage JSON API
  1. Navigate to APIs & auth > Credentials and then:
  • If you want to use a new service account, click on Create new client ID. After the account is created, you will be prompted to download the JSON key file that the library uses to authorize your requests.
  • If you want to generate a new key for an existing service account, click on Generate new JSON key and download the JSON key file.

Google Cloud Datastore

Google Cloud Datastore (docs) is a fully managed, schemaless database for storing non-relational data. Cloud Datastore automatically scales with your users and supports ACID transactions, high availability of reads and writes, strong consistency for reads and ancestor queries, and eventual consistency for all other queries.

Follow the activation instructions to use the Google Cloud Datastore API with your project.

See the gcloud-node Datastore API documentation to learn how to interact with the Cloud Datastore using this library.

var gcloud = require('gcloud');
var dataset;

// From Google Compute Engine:
dataset = gcloud.datastore.dataset({
  projectId: 'my-project'
});

// Or from elsewhere:
dataset = gcloud.datastore.dataset({
  projectId: 'my-project',
  keyFilename: '/path/to/keyfile.json'
});

dataset.get(dataset.key(['Product', 'Computer']), function(err, entity) {
  console.log(err || entity);
});

Google Cloud Storage

Google Cloud Storage (docs) allows you to store data on Google infrastructure with very high reliability, performance and availability, and can be used to distribute large data objects to users via direct download.

If you don't have a bucket already, follow the steps of the Creating a Bucket guide to learn how to create your own.

See the gcloud-node Storage API documentation to learn how to connect to Cloud Storage using this library.

var gcloud = require('gcloud');
var bucket;

// From Google Compute Engine:
bucket = gcloud.storage.bucket({
  projectId: 'my-project',
  bucketName: 'my-bucket'
});

// Or from elsewhere:
bucket = gcloud.storage.bucket({
  projectId: 'my-project',
  keyFilename: '/path/to/keyfile.json',
  bucketName: 'my-bucket'
});

bucket.write('demo.txt', 'Hello World', function(err) {
  console.log(err || 'Created demo.txt');
});

Google Cloud Pub/Sub (Alpha)

Google Cloud Pub/Sub is in Alpha status. As a result, it might change in backward-incompatible ways and is not recommended for production use. It is not subject to any SLA or deprecation policy.

Google Cloud Pub/Sub (docs) allows you to connect your services with reliable, many-to-many, asynchronous messaging hosted on Google's infrastructure. Cloud Pub/Sub automatically scales as you need it and provides a foundation for building your own robust, global services.

See the gcloud-node Pub/Sub API documentation to learn how to use Cloud Pub/Sub with this library.

var gcloud = require('gcloud');
var pubsub;

// From Google Compute Engine:
pubsub = gcloud.pubsub();

// Or from elsewhere:
pubsub = gcloud.pubsub({
  projectId: 'my-project',
  keyFilename: '/path/to/keyfile.json'
});

// Create a new topic.
pubsub.createTopic('my-new-topic', function(err, topic) {});

// Reference an existing topic.
var topic = pubsub.topic('my-existing-topic');

// Publish a message to the topic.
topic.publish('New message!', function(err) {});

// Subscribe to the topic.
topic.subscribe('new-subscription', function(err, subscription) {
  // Register listeners to start pulling for messages.
  function onError(err) {}
  function onMessage(message) {}
  subscription.on('error', onError);
  subscription.on('message', onMessage);

  // Remove listeners to stop pulling for messages.
  subscription.removeListener('message', onMessage);
  subscription.removeListener('error', onError);
});

Contributing

Contributions to this library are always welcome and highly encouraged.

See CONTRIBUTING for more information on how to get started.

License

Apache 2.0 - See COPYING for more information.

About

Google Cloud Node Client Library

Resources

License

Stars

Watchers

Forks

Packages

No packages published

Languages

  • JavaScript 88.4%
  • CSS 11.1%
  • Shell 0.5%