Convert Figma logo to code with AI

googleapis logogoogle-cloud-node

Google Cloud Client Library for Node.js

2,899
590
2,899
134

Top Related Projects

Modularized AWS SDK for JavaScript.

Firebase Javascript SDK

Node.js helper library

Node.js library for the Stripe API.

The Official Twilio SendGrid Led, Community Driven Node.js API Library

Quick Overview

googleapis/google-cloud-node is the official Node.js client library for Google Cloud Platform services. It provides a comprehensive set of tools and APIs to interact with various Google Cloud services, making it easier for developers to integrate Google Cloud functionality into their Node.js applications.

Pros

  • Comprehensive coverage of Google Cloud services
  • Official library maintained by Google, ensuring reliability and up-to-date features
  • Well-documented with extensive examples and guides
  • Supports both CommonJS and ES modules

Cons

  • Large package size due to the extensive coverage of services
  • Learning curve can be steep for beginners due to the wide range of features
  • Some services may have limited functionality compared to their REST API counterparts
  • Frequent updates may require occasional code adjustments

Code Examples

  1. Initializing a Cloud Storage client:
import { Storage } from '@google-cloud/storage';

const storage = new Storage();
  1. Uploading a file to Cloud Storage:
async function uploadFile(bucketName, fileName, filePath) {
  await storage.bucket(bucketName).upload(filePath, {
    destination: fileName,
  });
  console.log(`${fileName} uploaded to ${bucketName}`);
}
  1. Using BigQuery to run a query:
import { BigQuery } from '@google-cloud/bigquery';

const bigquery = new BigQuery();

async function runQuery() {
  const query = 'SELECT name, COUNT(*) as count FROM `bigquery-public-data.usa_names.usa_1910_2013` GROUP BY name ORDER BY count DESC LIMIT 10';
  const [job] = await bigquery.createQueryJob({ query });
  const [rows] = await job.getQueryResults();
  console.log(rows);
}

Getting Started

  1. Install the desired Google Cloud service package:

    npm install @google-cloud/storage
    
  2. Set up authentication:

    • Create a service account and download the JSON key file
    • Set the GOOGLE_APPLICATION_CREDENTIALS environment variable to the path of the JSON key file
  3. Use the library in your code:

    import { Storage } from '@google-cloud/storage';
    
    const storage = new Storage();
    
    async function listBuckets() {
      const [buckets] = await storage.getBuckets();
      console.log('Buckets:');
      buckets.forEach(bucket => {
        console.log(bucket.name);
      });
    }
    
    listBuckets().catch(console.error);
    

Competitor Comparisons

Modularized AWS SDK for JavaScript.

Pros of aws-sdk-js-v3

  • Modular architecture allows for smaller bundle sizes and improved performance
  • Supports both Node.js and browser environments
  • Comprehensive documentation and extensive examples

Cons of aws-sdk-js-v3

  • Steeper learning curve due to more complex API structure
  • Requires more setup and configuration compared to google-cloud-node
  • Less integrated with other cloud services outside of AWS ecosystem

Code Comparison

aws-sdk-js-v3:

import { S3Client, PutObjectCommand } from "@aws-sdk/client-s3";

const client = new S3Client({ region: "us-west-2" });
const command = new PutObjectCommand({
  Bucket: "my-bucket",
  Key: "my-file",
  Body: "Hello, World!",
});

google-cloud-node:

const { Storage } = require('@google-cloud/storage');

const storage = new Storage();
const bucket = storage.bucket('my-bucket');
const file = bucket.file('my-file');
file.save('Hello, World!');

The aws-sdk-js-v3 code demonstrates a more modular approach, importing specific clients and commands. It requires more setup but offers finer control. The google-cloud-node code is more concise and straightforward, with a simpler API structure that may be easier for beginners to understand and use.

Firebase Javascript SDK

Pros of firebase-js-sdk

  • Simplified API for common web and mobile app features
  • Real-time database and synchronization capabilities
  • Comprehensive authentication and user management

Cons of firebase-js-sdk

  • Less flexibility for advanced cloud operations
  • Limited customization options compared to google-cloud-node
  • Potential vendor lock-in to Firebase ecosystem

Code Comparison

firebase-js-sdk:

import { initializeApp } from 'firebase/app';
import { getFirestore, collection, addDoc } from 'firebase/firestore';

const app = initializeApp(firebaseConfig);
const db = getFirestore(app);
await addDoc(collection(db, 'users'), { name: 'John', age: 30 });

google-cloud-node:

const { Firestore } = require('@google-cloud/firestore');

const firestore = new Firestore();
await firestore.collection('users').add({ name: 'John', age: 30 });

The firebase-js-sdk offers a more streamlined API for common app development tasks, while google-cloud-node provides greater flexibility and access to a wider range of Google Cloud services. firebase-js-sdk is ideal for rapid development of web and mobile apps, particularly those requiring real-time features. google-cloud-node is better suited for more complex cloud applications and services that need fine-grained control over Google Cloud resources.

Node.js helper library

Pros of twilio-node

  • Simpler API structure, focusing on a specific set of communication services
  • More comprehensive documentation with code examples for each API endpoint
  • Faster release cycle with more frequent updates

Cons of twilio-node

  • Limited scope compared to google-cloud-node's broader range of services
  • Less integration with other cloud services
  • Smaller community and ecosystem

Code Comparison

twilio-node:

const client = require('twilio')(accountSid, authToken);

client.messages
  .create({
     body: 'Hello from Node',
     from: '+15017122661',
     to: '+15558675310'
   })
  .then(message => console.log(message.sid));

google-cloud-node:

const {PubSub} = require('@google-cloud/pubsub');
const pubsub = new PubSub();

async function publishMessage() {
  const topicName = 'my-topic';
  const data = JSON.stringify({foo: 'bar'});
  const messageId = await pubsub.topic(topicName).publish(Buffer.from(data));
  console.log(`Message ${messageId} published.`);
}

Both libraries offer straightforward APIs for their respective services. twilio-node focuses on communication services with a simple client-based approach, while google-cloud-node provides a more extensive set of cloud services with a modular structure. The choice between them depends on the specific needs of your project and the range of services required.

Node.js library for the Stripe API.

Pros of stripe-node

  • Focused solely on payment processing, offering a more streamlined and specialized API
  • Extensive documentation and examples for common payment scenarios
  • Regular updates and active community support

Cons of stripe-node

  • Limited to Stripe's payment services, lacking the broader cloud functionality of google-cloud-node
  • May require additional integrations for non-payment related features

Code Comparison

stripe-node:

const stripe = require('stripe')('sk_test_...');
const paymentIntent = await stripe.paymentIntents.create({
  amount: 1000,
  currency: 'usd',
  payment_method_types: ['card'],
});

google-cloud-node:

const {Storage} = require('@google-cloud/storage');
const storage = new Storage();
const [files] = await storage.bucket('my-bucket').getFiles();
files.forEach(file => {
  console.log(file.name);
});

The code snippets demonstrate the difference in focus between the two libraries. stripe-node is tailored for payment processing, while google-cloud-node provides access to various Google Cloud services, such as storage in this example.

Both libraries offer promise-based APIs and follow Node.js conventions, making them easy to integrate into existing projects. However, the scope and use cases for each library differ significantly, with stripe-node being more specialized and google-cloud-node offering broader cloud functionality.

The Official Twilio SendGrid Led, Community Driven Node.js API Library

Pros of sendgrid-nodejs

  • Focused specifically on email sending, providing a streamlined API for this purpose
  • Extensive documentation and examples for various email-related tasks
  • Simpler setup process for basic email functionality

Cons of sendgrid-nodejs

  • Limited to email-related features, unlike the broader Google Cloud SDK
  • May require additional libraries for more complex cloud-based operations
  • Less integration with other cloud services compared to google-cloud-node

Code Comparison

sendgrid-nodejs:

const sgMail = require('@sendgrid/mail');
sgMail.setApiKey(process.env.SENDGRID_API_KEY);
const msg = {
  to: 'recipient@example.com',
  from: 'sender@example.com',
  subject: 'Hello World',
  text: 'This is a test email from SendGrid',
};
sgMail.send(msg);

google-cloud-node:

const {Storage} = require('@google-cloud/storage');
const storage = new Storage();
async function createBucket() {
  await storage.createBucket('my-bucket');
  console.log('Bucket created successfully.');
}
createBucket();

The code examples highlight the difference in focus between the two libraries. sendgrid-nodejs provides a straightforward way to send emails, while google-cloud-node offers a broader range of cloud services, such as storage management in this example. The choice between these libraries depends on the specific needs of your project and the extent of cloud services required.

Convert Figma logo designs to code with AI

Visual Copilot

Introducing Visual Copilot: A new AI model to turn Figma designs to high quality code using your components.

Try Visual Copilot

README

Google Cloud Node.js Client Libraries

Node.js idiomatic client libraries for Google Cloud Platform services.

Libraries are available on GitHub and npm for developing Node.js applications that interact with individual Google Cloud services:

RepoRelease LevelVersion
Access ApprovalStablenpm
Access Context ManagerStablenpm
Advisory Notifications APIStablenpm
AI Platform NotebooksStablenpm
AlloyDB APIStablenpm
Analytics Hub APIStablenpm
Anthos Multi-Cloud APIStablenpm
API GatewayStablenpm
API Keys APIStablenpm
Apigee Connect APIStablenpm
App Engine Admin APIStablenpm
Artifact RegistryStablenpm
Asset InventoryStablenpm
Assured Workloads for GovernmentStablenpm
AutoMLStablenpm
Backup and DR Service APIStablenpm
Backup for GKE APIStablenpm
Bare Metal Solution APIStablenpm
BeyondCorp APIStablenpm
BeyondCorp APIStablenpm
BigQuery Migration APIStablenpm
BigtableStablenpm
BillingStablenpm
Billing BudgetsStablenpm
Binary AuthorizationStablenpm
BuildStablenpm
Certificate Authority ServiceStablenpm
Certificate ManagerStablenpm
Channel APIStablenpm
Commerce Consumer Procurement APIStablenpm
ComposerStablenpm
Confidential Computing APIStablenpm
Connectors APIStablenpm
Contact Center AI Insights APIStablenpm
Controls Partner APIStablenpm
Data CatalogStablenpm
Data FusionStablenpm
Data Lineage APIStablenpm
Data Loss PreventionStablenpm
Database Migration ServiceStablenpm
DataplexStablenpm
DataprocStablenpm
Dataproc MetastoreStablenpm
DatastoreStablenpm
Datastore SessionStablenpm
DatastreamStablenpm
DeployStablenpm
Dialogflow APIStablenpm
Dialogflow CX APIStablenpm
Discovery Engine APIStablenpm
Distributed Cloud Edge Container APIStablenpm
Distributed Cloud Edge Network APIStablenpm
DNSStablenpm
Document AIStablenpm
Document AI WarehouseStablenpm
DomainsStablenpm
Error ReportingStablenpm
Essential Contacts APIStablenpm
EventarcStablenpm
Eventarc Publishing APIStablenpm
FilestoreStablenpm
FirestoreStablenpm
Firestore SessionStablenpm
FunctionsStablenpm
GKE HubStablenpm
Google BigQueryStablenpm
Google BigQuery ConnectionStablenpm
Google BigQuery Data Transfer ServiceStablenpm
Google BigQuery ReservationStablenpm
Google BigQuery StorageStablenpm
Google Compute EngineStablenpm
Google Container AnalysisStablenpm
Google Workspace Add-ons APIStablenpm
GrafeasStablenpm
IAM Policy Troubleshooter APIStablenpm
IAM Service Account Credentials APIStablenpm
Identity and Access ManagementStablenpm
Identity-Aware ProxyStablenpm
IDSStablenpm
Infrastructure Manager APIStablenpm
Internet of Things (IoT) CoreStablenpm
Key Management ServiceStablenpm
Kubernetes Engine Cluster Manager APIStablenpm
Live Stream APIStablenpm
LoggingStablenpm
Logging for BunyanStablenpm
Logging for WinstonStablenpm
Managed Service for Microsoft Active DirectoryStablenpm
Media TranslationStablenpm
Memorystore for MemcachedStablenpm
Migrate for Compute EngineStablenpm
Migration Center APIStablenpm
Monitoring DashboardsStablenpm
Natural LanguageStablenpm
NetApp APIStablenpm
Network Connectivity CenterStablenpm
Network Management APIStablenpm
Network Security APIStablenpm
Network Services APIStablenpm
Optimization AIStablenpm
Organization PolicyStablenpm
OS Config APIStablenpm
OS LoginStablenpm
Policy Simulator APIStablenpm
ProfilerStablenpm
Pub/SubStablenpm
Public Certificate AuthorityStablenpm
Quotas APIStablenpm
Rapid Migration Assessment APIStablenpm
reCAPTCHA EnterpriseStablenpm
RecommenderStablenpm
RedisStablenpm
Resource Manager APIStablenpm
Retail APIStablenpm
RunStablenpm
SchedulerStablenpm
Secret ManagerStablenpm
Secure Source Manager APIStablenpm
Security Center Management APIStablenpm
Security Command CenterStablenpm
Service Control APIStablenpm
Service DirectoryStablenpm
Service Health APIStablenpm
Service Management APIStablenpm
Service UsageStablenpm
ShellStablenpm
SpannerStablenpm
SpeechStablenpm
SQL Admin APIStablenpm
Stackdriver MonitoringStablenpm
StorageStablenpm
Storage APIStablenpm
Storage Insights APIStablenpm
Storage Transfer ServiceStablenpm
Support APIStablenpm
Talent SolutionStablenpm
TasksStablenpm
Telco Automation APIStablenpm
Text-to-SpeechStablenpm
TPUStablenpm
Transcoder APIStablenpm
TranslationStablenpm
Vertex AIStablenpm
Video IntelligenceStablenpm
Video Stitcher APIStablenpm
Virtual Private CloudStablenpm
Vision APIStablenpm
VMware Engine APIStablenpm
Web Risk APIStablenpm
Web Security ScannerStablenpm
Workflow ExecutionsStablenpm
Workstations APIStablenpm
Previewnpm
Apache Kafka for BigQuery APIPreviewnpm
Apigee Registry APIPreviewnpm
App Hub APIPreviewnpm
Area120 Tables APIPreviewnpm
BatchPreviewnpm
BeyondCorp APIPreviewnpm
BeyondCorp APIPreviewnpm
BeyondCorp APIPreviewnpm
CSS APIPreviewnpm
Data LabelingPreviewnpm
Data QnAPreviewnpm
DataflowPreviewnpm
Dataform APIPreviewnpm
Developer Connect APIPreviewnpm
GDC Hardware Management APIPreviewnpm
Generative Language APIPreviewnpm
GKE Connect GatewayPreviewnpm
Google Analytics AdminPreviewnpm
Google Analytics DataPreviewnpm
Google Chat APIPreviewnpm
Google Maps RoutingPreviewnpm
Google Meet APIPreviewnpm
Last Mile Fleet Solution Delivery APIPreviewnpm
Life SciencesPreviewnpm
Local Rides and Deliveries APIPreviewnpm
Memorystore for Redis APIPreviewnpm
Merchant APIPreviewnpm
Merchant APIPreviewnpm
Merchant APIPreviewnpm
Merchant APIPreviewnpm
Merchant APIPreviewnpm
Merchant APIPreviewnpm
Merchant APIPreviewnpm
Merchant APIPreviewnpm
Merchant APIPreviewnpm
Parallelstore APIPreviewnpm
Phishing ProtectionPreviewnpm
Places API (New)Previewnpm
Policy Troubleshooter APIPreviewnpm
Private CatalogPreviewnpm
Privileged Access Manager APIPreviewnpm
Profiler APIPreviewnpm
Route Optimization APIPreviewnpm
Solar APIPreviewnpm
TracePreviewnpm
Vertex AIPreviewnpm

If the service is not listed above, google-api-nodejs-client interfaces with additional Google Cloud APIs using a legacy REST interface.

When building Node.js applications, preference should be given to the libraries listed in the table.

Enabling APIs

Before you can interact with a given Google Cloud Service, you must enable its API.

Links are available for enabling APIs in the table at the beginning of this document, and in each libraries README.md.

Authentication

Download your Service Account Credentials JSON file

To use Application Default Credentials, You first need to download a set of JSON credentials for your project. Go to APIs & Auth > Credentials in the Google Developers Console and select Service account from the Add credentials dropdown.

This file is your only copy of these credentials. It should never be committed with your source code, and should be stored securely.

Once downloaded, store the path to this file in the GOOGLE_APPLICATION_CREDENTIALS environment variable.

Other Authentication Methods

Other authentication methods are outlined in the README for google-auth-library-nodejs, which is the authentication library used by all Google Cloud Node.js clients.

Example Applications

  • nodejs-getting-started - A sample and tutorial that demonstrates how to build a complete web application using Cloud Datastore, Cloud Storage, and Cloud Pub/Sub and deploy it to Google App Engine or Google Compute Engine.
  • gcloud-node-todos - A TodoMVC backend using google-cloud-node and Datastore.
  • gitnpm - Easily lookup an npm package's GitHub repo using google-cloud-node and Google App Engine.
  • gcloud-kvstore - Use Datastore as a simple key-value store.
  • hya-wave - Cloud-based web sample editor. Part of the hya-io family of products.
  • gstore-node - Google Datastore Entities Modeling library.
  • gstore-api - REST API builder for Google Datastore Entities.

Supported Node.js Versions

Our client libraries follow the Node.js release schedule. Libraries are compatible with all current active and maintenance versions of Node.js. If you are using an end-of-life version of Node.js, we recommend that you update as soon as possible to an actively supported LTS version.

Google's client libraries support legacy versions of Node.js runtimes on a best-efforts basis with the following warnings:

  • Legacy versions are not tested in continuous integration.
  • Some security patches and features cannot be backported.
  • Dependencies cannot be kept up-to-date.

Client libraries targeting some end-of-life versions of Node.js are available, and can be installed through npm dist-tags. The dist-tags follow the naming convention legacy-(version). For example, {{ metadata['lib_install_cmd'] }}@legacy-10 installs client libraries for versions compatible with Node.js 10.

Versioning

Our libraries follow Semantic Versioning.

Please note it is currently under active development. Any release versioned 0.x.y is subject to backwards-incompatible changes at any time.

Stable: Libraries defined at the Stable quality level are stable. The code surface will not change in backwards-incompatible ways unless absolutely necessary (e.g. because of critical security issues) or with an extensive deprecation period. Issues and requests against Stable libraries are addressed with the highest priority.

Preview: Libraries defined at the preview quality level are still a work-in-progress and are more likely to get backwards-incompatible updates.

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 LICENSE for more information.

NPM DownloadsLast 30 Days