Research
Security News
Malicious npm Package Targets Solana Developers and Hijacks Funds
A malicious npm package targets Solana developers, rerouting funds in 2% of transactions to a hardcoded address.
gcloud
is deprecated!Node.js idiomatic client for Google Cloud Platform services.
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.
$ npm install --save gcloud
With gcloud-node
it's incredibly easy to get authenticated and start using Google's APIs. You can set your credentials on a global basis as well as on a per-API basis. See each individual API section below to see how you can auth on a per-API-basis. This is useful if you want to use different accounts for different Google Cloud services.
If you are running this client on Google Compute Engine, we handle authentication 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.
// Authenticating on a global basis.
var projectId = process.env.GCLOUD_PROJECT; // E.g. 'grape-spaceship-123'
var gcloud = require('gcloud')({
projectId: projectId
});
// ...you're good to go! See the next section to get started using the APIs.
If you are not running this client on Google Compute Engine, you need a Google Developers service account. To create a service account:
// Authenticating on a global basis.
var projectId = process.env.GCLOUD_PROJECT; // E.g. 'grape-spaceship-123'
var gcloud = require('gcloud')({
projectId: projectId,
keyFilename: '/path/to/keyfile.json'
});
// ...you're good to go! See the next section to get started using the APIs.
You can also set auth on a per-API-instance basis. The examples below show you how.
var gcloud = require('gcloud');
// Authenticating on a per-API-basis. You don't need to do this if you auth on a
// global basis (see Authentication section above).
var bigquery = gcloud.bigquery({
projectId: 'my-project',
keyFilename: '/path/to/keyfile.json'
});
// Access an existing dataset and table.
var schoolsDataset = bigquery.dataset('schools');
var schoolsTable = schoolsDataset.table('schoolsData');
// Import data into a table.
schoolsTable.import('/local/file.json', function(err, job) {});
// Get results from a query job.
var job = bigquery.job('job-id');
// Use a callback.
job.getQueryResults(function(err, rows) {});
// Or get the same results as a readable stream.
job.getQueryResults().on('data', function(row) {});
You may need to create a cluster to use the Google Cloud Bigtable API with your project.
var gcloud = require('gcloud');
// Authenticating on a per-API-basis. You don't need to do this if you auth on a
// global basis (see Authentication section above).
var bigtable = gcloud.bigtable({
projectId: 'my-project',
keyFilename: '/path/to/keyfile.json',
zone: 'my-zone',
cluster: 'my-cluster'
});
var table = bigtable.table('prezzy');
table.getRows(function(err, rows) {});
// Update a row in your table.
var row = table.row('alincoln');
row.save('follows:gwashington', 1, function(err) {
if (err) {
// Error handling omitted.
}
row.get('follows:gwashington', function(err, data) {
if (err) {
// Error handling omitted.
}
// data = {
// follows: {
// gwashington: [
// {
// value: 1
// }
// ]
// }
// }
});
});
Follow the activation instructions to use the Google Cloud Datastore API with your project.
var gcloud = require('gcloud');
// Authenticating on a per-API-basis. You don't need to do this if you auth on a
// global basis (see Authentication section above).
var datastore = gcloud.datastore({
projectId: 'my-project',
keyFilename: '/path/to/keyfile.json'
});
var key = datastore.key(['Product', 'Computer']);
datastore.get(key, function(err, entity) {
console.log(err || entity);
});
// Save data to Datastore.
var blogPostData = {
title: 'How to make the perfect homemade pasta',
author: 'Andrew Chilton',
isDraft: true
};
var blogPostKey = datastore.key('BlogPost');
datastore.save({
key: blogPostKey,
data: blogPostData
}, function(err) {
// `blogPostKey` has been updated with an ID so you can do more operations
// with it, such as an update.
blogPostData.isDraft = false;
datastore.save({
key: blogPostKey,
data: blogPostData
}, function(err) {
if (!err) {
// The blog post is now published!
}
});
});
var gcloud = require('gcloud');
// Authenticating on a per-API-basis. You don't need to do this if you auth on a
// global basis (see Authentication section above).
var dns = gcloud.dns({
projectId: 'my-project',
keyFilename: '/path/to/keyfile.json'
});
// Create a managed zone.
dns.createZone('my-new-zone', {
dnsName: 'my-domain.com.'
}, function(err, zone) {});
// Reference an existing zone.
var zone = dns.zone('my-existing-zone');
// Create an NS record.
var nsRecord = zone.record('ns', {
ttl: 86400,
name: 'my-domain.com.',
data: 'ns-cloud1.googledomains.com.'
});
zone.addRecord(nsRecord, function(err, change) {});
// Create a zonefile from the records in your zone.
zone.export('/zonefile.zone', function(err) {});
var gcloud = require('gcloud');
// Authenticating on a per-API-basis. You don't need to do this if you
// auth on a global basis (see Authentication section above).
var pubsub = gcloud.pubsub({
projectId: 'my-project',
keyFilename: '/path/to/keyfile.json'
});
// Reference a topic that has been previously created.
var topic = pubsub.topic('my-topic');
// Publish a message to the topic.
topic.publish({
data: 'New message!'
}, function(err) {});
// Subscribe to the topic.
var options = {
reuseExisting: true
};
topic.subscribe('subscription-name', options, 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);
});
var fs = require('fs');
var gcloud = require('gcloud');
// Authenticating on a per-API-basis. You don't need to do this if you auth on a
// global basis (see Authentication section above).
var gcs = gcloud.storage({
projectId: 'my-project',
keyFilename: '/path/to/keyfile.json'
});
// Create a new bucket.
gcs.createBucket('my-new-bucket', function(err, bucket) {
if (!err) {
// "my-new-bucket" was successfully created.
}
});
// Reference an existing bucket.
var bucket = gcs.bucket('my-existing-bucket');
// Upload a local file to a new file to be created in your bucket.
bucket.upload('/photos/zoo/zebra.jpg', function(err, file) {
if (!err) {
// "zebra.jpg" is now in your bucket.
}
});
// Download a file from your bucket.
bucket.file('giraffe.jpg').download({
destination: '/photos/zoo/giraffe.jpg'
}, function(err) {});
// Streams are also supported for reading and writing files.
var remoteReadStream = bucket.file('giraffe.jpg').createReadStream();
var localWriteStream = fs.createWriteStream('/photos/zoo/giraffe.jpg');
remoteReadStream.pipe(localWriteStream);
var localReadStream = fs.createReadStream('/photos/zoo/zebra.jpg');
var remoteWriteStream = bucket.file('zebra.jpg').createWriteStream();
localReadStream.pipe(remoteWriteStream);
var gcloud = require('gcloud');
// Authenticating on a per-API-basis. You don't need to do this if you auth on a
// global basis (see Authentication section above).
var gce = gcloud.compute({
projectId: 'my-project',
keyFilename: '/path/to/keyfile.json'
});
// Create a new VM using the latest OS image of your choice.
var zone = gce.zone('us-central1-a');
var name = 'ubuntu-http';
zone.createVM(name, { os: 'ubuntu' }, function(err, vm, operation) {
// `operation` lets you check the status of long-running tasks.
operation
.on('error', function(err) {})
.on('running', function(metadata) {})
.on('complete', function(metadata) {
// Virtual machine created!
});
});
var gcloud = require('gcloud');
// Authenticating on a per-API-basis. You don't need to do this if you auth on a
// global basis (see Authentication section above).
var prediction = gcloud.prediction({
projectId: 'my-project',
keyFilename: '/path/to/keyfile.json'
});
// Get all of the trained models in your project.
prediction.getModels(function(err, models) {
if (!err) {
// `models` is an array of Model objects.
}
});
// Reference an existing trained model.
var model = prediction.model('my-existing-model');
// Train a model.
model.train('english', 'Hello from your friends at Google!', function(err) {});
// Query a model.
model.query('Hello', function(err, results) {
if (!err) {
// results.winner == 'english'
// results.scores == [
// {
// label: 'english',
// score: 1
// },
// {
// label: 'spanish',
// score: 0
// }
// ]
}
});
An API key is required for Translate. See Identifying your application to Google.
var gcloud = require('gcloud');
// Authenticating on a per-API-basis. You don't need to do this if you auth on a
// global basis (see Authentication section above).
var translate = gcloud.translate({
key: 'API Key'
});
// Translate a string of text.
translate.translate('Hello', 'es', function(err, translation) {
if (!err) {
// translation = 'Hola'
}
});
// Detect a language from a string of text.
translate.detect('Hello', function(err, results) {
if (!err) {
// results = {
// language: 'en',
// confidence: 1,
// input: 'Hello'
// }
}
});
// Get a list of supported languages.
translate.getLanguages(function(err, languages) {
if (!err) {
// languages = [
// 'af',
// 'ar',
// 'az',
// ...
// ]
}
});
This is a Beta release of Google Cloud Logging. This API is not covered by any SLA or deprecation policy and may be subject to backward-incompatible changes.
// Authenticating on a global-basis. You can also authenticate on a per-API-
// basis (see Authentication section above).
var gcloud = require('gcloud')({
projectId: 'my-project',
keyFilename: '/path/to/keyfile.json'
});
var logging = gcloud.logging();
// Create a sink using a Bucket as a destination.
var gcs = gcloud.storage();
logging.createSink('my-new-sink', {
destination: gcs.bucket('my-sink')
}, function(err, sink) {});
// Write a critical entry to a log.
var syslog = logging.log('syslog');
var resource = {
type: 'gce_instance',
labels: {
zone: 'global',
instance_id: '3'
}
};
var entry = syslog.entry(resource, {
delegate: process.env.user
});
syslog.critical(entry, function(err) {});
// Get all entries in your project.
logging.getEntries(function(err, entries) {
if (!err) {
// `entries` contains all of the entries from the logs in your project.
}
});
This is a Beta release of Google Cloud Resource Manager. This feature is not covered by any SLA or deprecation policy and may be subject to backward-incompatible changes.
var gcloud = require('gcloud');
// Authorizing on a per-API-basis. You don't need to do this if you auth on a
// global basis (see Authorization section above).
var resource = gcloud.resource({
projectId: 'my-project',
keyFilename: '/path/to/keyfile.json'
});
// Get all of the projects you maintain.
resource.getProjects(function(err, projects) {
if (!err) {
// `projects` contains all of your projects.
}
});
// Get the metadata from your project. (defaults to `my-project`)
var project = resource.project();
project.getMetadata(function(err, metadata) {
// `metadata` describes your project.
});
This is a Beta release of Google Cloud Vision. This feature is not covered by any SLA or deprecation policy and may be subject to backward-incompatible changes.
var gcloud = require('gcloud');
// Authorizing on a per-API-basis. You don't need to do this if you auth on a
// global basis (see Authorization section above).
var vision = gcloud.vision({
projectId: 'my-project',
keyFilename: '/path/to/keyfile.json'
});
// Read the text from an image.
vision.detectText('./image.jpg', function(err, text) {
// text = [
// 'This was text found in the image',
// 'This was more text found in the image'
// ]
});
// Detect faces and the locations of their features in an image.
vision.detectFaces('./image.jpg', function(err, faces) {
// faces = [
// {
// angles: {pan,tilt,roll},
// bounds: {
// head: [{x,y},{x,y},{x,y},{x,y}],
// face: [{x,y},{x,y},{x,y},{x,y}]
// },
// features: {
// confidence: 34.489909,
// chin: {
// center: {x,y,z},
// left: {x,y,z},
// right: {x,y,z}
// },
// ears: {
// left: {x,y,z},
// right: {x,y,z}
// },
// eyebrows: {
// left: {
// left: {x,y,z},
// right: {x,y,z},
// top: {x,y,z}
// },
// right: {
// left: {x,y,z},
// right: {x,y,z},
// top: {x,y,z}
// }
// },
// eyes: {
// left: {
// bottom: {x,y,z},
// center: {x,y,z},
// left: {x,y,z},
// pupil: {x,y,z},
// right: {x,y,z},
// top: {x,y,z}
// },
// right: {
// bottom: {x,y,z},
// center: {x,y,z},
// left: {x,y,z},
// pupil: {x,y,z},
// right: {x,y,z},
// top: {x,y,z}
// }
// },
// forehead: {x,y,z},
// lips: {
// bottom: {x,y,z},
// top: {x,y,z}
// },
// mouth: {
// center: {x,y,z},
// left: {x,y,z},
// right: {x,y,z}
// },
// nose: {
// bottom: {
// center: {x,y,z},
// left: {x,y,z},
// right: {x,y,z}
// },
// tip: {x,y,z},
// top: {x,y,z}
// }
// },
// confidence: 56.748849,
// blurry: false,
// dark: false,
// happy: false,
// hat: false,
// mad: false,
// sad: false,
// surprised: false
// }
// ]
});
Contributions to this library are always welcome and highly encouraged.
See CONTRIBUTING for more information on how to get started.
Apache 2.0 - See COPYING for more information.
FAQs
Google Cloud APIs Client Library for Node.js
The npm package gcloud receives a total of 1,784 weekly downloads. As such, gcloud popularity was classified as popular.
We found that gcloud demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 5 open source maintainers collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Research
Security News
A malicious npm package targets Solana developers, rerouting funds in 2% of transactions to a hardcoded address.
Security News
Research
Socket researchers have discovered malicious npm packages targeting crypto developers, stealing credentials and wallet data using spyware delivered through typosquats of popular cryptographic libraries.
Security News
Socket's package search now displays weekly downloads for npm packages, helping developers quickly assess popularity and make more informed decisions.