You can use the google-cloud client library for Node.js to accomplish this. The same library is also available for Java, Python and Ruby.
For example, in Node JS, you must edit the package.json file accordingly:
{ "dependencies": { "google-cloud": "*" }, ... }
Then in your code you can just call the appropriate library. The following example lists only the buckets in the project:
var gcloud = require('google-cloud'); exports.helloworld = function(context, data) { var gcs = gcloud.storage({projectId: '<PROJECT>'}); gcs.getBuckets(function(err, buckets) { if (!err) { buckets.forEach(function(bucket) { console.log(bucket.name); }); } else { console.log('error: ' + err); } }); context.success(); }
You should also not include the entire google-cloud npm module, but instead specify a specific submodule, for example. require('@google-cloud/storage') in the above example.
source share