Registry / cloud / grpc-gcp

grpc-gcp

JSON →
library1.0.1jsnpmunverified

A Node.js module (v1.0.1, updated Aug 2022, infrequent releases) extending gRPC with Google Cloud Platform-specific features like channel pooling and affinity-based routing. It provides a GcpApiConfig from a JSON definition, a custom channel factory override, and a call invocation transformer to enable features such as BIND/BOUND/UNBIND affinity commands. Works with both 'grpc' and '@grpc/grpc-js' packages via a factory pattern. Differentiated by its GCP-specific optimizations over plain gRPC.

npm install grpc-gcp
INSTALL
IMPORT
SIG · GRPC-GCP
G
grpc-gcp
cloudjavascriptv1.0.1
harness data pending
Install & Compatibility
Where this runs

No compatibility data collected yet for this library.

Code
Verified usage

Verified import paths — ran on the pinned version, not inferred.

grpcGcp
import grpcGcp from 'grpc-gcp'
const grpcGcp = require('grpc-gcp');
Default export expected; library ships TypeScript types but is primarily CJS.
createGcpApiConfig
import { createGcpApiConfig } from 'grpc-gcp'
const { createGcpApiConfig } = require('grpc-gcp');
Named export available as well.
grpc
import grpc from 'grpc'; const grpcGcp = require('grpc-gcp')(grpc);
import grpcGcp from 'grpc-gcp'; import grpc from 'grpc'; grpcGcp(grpc);
Library is called as a function with grpc instance; typical pattern: require('grpc-gcp')(grpc).

Initialize gRPC-GCP with a GCP API config, then create a Spanner client with channel pool and affinity features.

const grpc = require('grpc'); const grpcGcp = require('grpc-gcp')(grpc); const fs = require('fs'); const apiDefinition = JSON.parse(fs.readFileSync('your_api_config.json')); const apiConfig = grpcGcp.createGcpApiConfig(apiDefinition); const channelOptions = { channelFactoryOverride: grpcGcp.gcpChannelFactoryOverride, callInvocationTransformer: grpcGcp.gcpCallInvocationTransformer, gcpApiConfig: apiConfig, }; const channelCreds = grpc.credentials.createInsecure(); const client = new SpannerClient( 'spanner.googleapis.com:443', channelCreds, channelOptions );
Debug
Known issues
breakingVersion 1.0.0 changed the export from a class to a function that takes grpc as argument.
fix
Use require('grpc-gcp')(grpc) instead of new GrpcGcp().
affects: >=1.0.0
gotchaThe channelFactoryOverride and callInvocationTransformer must be passed as strings (function references) in channel options, not as calls.
fix
Set channelFactoryOverride: grpcGcp.gcpChannelFactoryOverride, not channelFactoryOverride: grpcGcp.gcpChannelFactoryOverride().
affects: >=0.x
deprecatedThe 'grpc' package is deprecated; use '@grpc/grpc-js' instead.
fix
Replace require('grpc') with require('@grpc/grpc-js').
affects: >=0.x
Errors
Common errors & fixes
grpcGcp is not a constructor
Using new grpcGcp() where grpcGcp is now a function, not a class.
fix
Use require('grpc-gcp')(grpc) instead.
Cannot find module 'grpc'
grpc package not installed; it's a peer dependency.
fix
npm install grpc (or @grpc/grpc-js).
Upgrade
Version history
1.0.1latest on npm
Audit
Dependencies
grpcrequiredrequired core gRPC library for Node.js
Agent activity
11 hits · last 30 days
node
10
OpenAI (training)
1
Resources
grpc-gcp — npm install grpc-gcp · libregistry