Registry / testing / grpcjs-interceptors

grpcjs-interceptors

JSON →
library0.1.15jsnpmunverified

grpc-interceptors (v0.1.15) provides client and server interceptor middleware for Node.js gRPC, compensating for the lack of server-side interceptors in the official grpc-js library. This fork adds access to the RPC callback in interceptors, enabling error propagation (e.g., authentication rejection). Not actively maintained; consider gRPC's official interceptor support (available since grpc-js 1.4.0).

npm install grpcjs-interceptors
INSTALL
IMPORT
SIG · GRPCJS-INTERCEPTOR
G
grpcjs-interceptors
testingjavascriptv0.1.15
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.

serverProxy
const { serverProxy } = require('grpc-interceptors');
import { serverProxy } from 'grpc-interceptors';
Package is CJS-only; no ESM exports.
clientProxy
const { clientProxy } = require('grpc-interceptors');
const interceptors = require('grpc-interceptors'); const client = interceptors.clientProxy(new grpc.Client(...));
clientProxy wraps a grpc.Client instance.
default export (interceptors)
const interceptors = require('grpc-interceptors');
const interceptors = require('grpc-interceptors').default;
Package exports a namespace object with serverProxy and clientProxy.

Creates a gRPC server with interceptor middleware for authentication using metadata.

const grpc = require('@grpc/grpc-js'); const protoLoader = require('@grpc/proto-loader'); const interceptors = require('grpc-interceptors'); // Load proto and create server const packageDefinition = protoLoader.loadSync('service.proto'); const proto = grpc.loadPackageDefinition(packageDefinition); const server = interceptors.serverProxy(new grpc.Server()); server.addService(proto.mypackage.MyService.service, { myMethod: (call, callback) => { callback(null, { message: 'Hello ' + call.request.name }); } }); const myMiddleware = async (ctx, next, callback) => { // Authentication check const user = ctx.call.metadata.get('user')[0]; const pass = ctx.call.metadata.get('password')[0]; if (user === 'admin' && pass === 'secret') { await next(); } else { callback(new Error('Unauthorized')); } }; server.use(myMiddleware); server.bindAsync('0.0.0.0:50051', grpc.ServerCredentials.createInsecure(), () => { console.log('Server running...'); });
Debug
Known issues
deprecatedPackage is not actively maintained; consider using official grpc-js interceptor API (available since @grpc/grpc-js v1.4.0).
fix
Migrate to @grpc/grpc-js built-in interceptors.
affects: >=0.0.0
gotchaMetadata access via private internal property `_internal_repr` is fragile and may break across versions.
fix
Use `.get()` method on metadata object instead of `_internal_repr`.
affects: >=0.0.0
gotchaCallback must be called exactly once; not calling it will cause hangs.
fix
Always call `callback` or `next()` (which internally calls callback).
affects: >=0.1.0
gotchaServer-side interceptor context differs from client; client interceptor has different hook names (intercept vs use).
fix
Refer to original echo-health docs for client usage.
affects: >=0.0.0
Errors
Common errors & fixes
TypeError: ctx.call.metadata._internal_repr is undefined
Metadata structure changed in newer @grpc/grpc-js versions.
fix
Use ctx.call.metadata.get('key') instead.
Error: The callback must be called exactly once
Callback invoked more than once or not at all in interceptor.
fix
Ensure callback is called exactly once, either directly or via `await next()`.
Cannot find module 'grpc-interceptors'
Package not installed; installation is via git URL.
fix
npm install git+https://github.com/mfecteau34/node-grpc-interceptors.git
Upgrade
Version history
0.1.15latest on npm
Audit
Dependencies
@grpc/grpc-jsrequiredPeer dependency required for gRPC functionality
lodashoptionalCommonly used in examples for accessing metadata; not a required dependency but typical
Agent activity
15 hits · last 30 days
node
14
Resources
grpcjs-interceptors — npm install grpcjs-interceptors · libregistry