Registry / backend / grpc-node-server-interceptors

grpc-node-server-interceptors

JSON →
library1.0.1jsnpmunverified

A library enabling interceptor support for gRPC servers built with `@grpc/grpc-js`. Current stable version is 1.0.2. Provides a drop-in replacement for `@grpc/grpc-js`'s Server class, allowing developers to intercept incoming client requests and outgoing server responses using a middleware-like pattern. Ideal for logging, authentication, error handling, monitoring, or request/response transformation without modifying existing handler code. Ships TypeScript definitions.

npm install grpc-node-server-interceptors
INSTALL
IMPORT
SIG · GRPC-NODE-SERVER-I
G
grpc-node-server-interceptors
backendjavascriptv1.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.

GrpcServerWithInterceptors
import GrpcServerWithInterceptors from 'grpc-node-server-interceptors'
const { GrpcServerWithInterceptors } = require('grpc-node-server-interceptors')
Default export is the class. CommonJS require with destructuring will fail because the default export is not an object.
ServerInterceptor
import { ServerInterceptor } from 'grpc-node-server-interceptors'
import ServerInterceptor from 'grpc-node-server-interceptors'
Named export, not default. Must use destructuring.
ServerInterceptingCall
import { ServerInterceptingCall } from 'grpc-node-server-interceptors'
const ServerInterceptingCall = require('grpc-node-server-interceptors').ServerInterceptingCall
CommonJS require is supported but TypeScript users should use ESM syntax. The class is a named export.

Creates a gRPC server with interceptors that logs incoming requests and error responses.

import { status as GrpcStatus } from '@grpc/grpc-js'; import GrpcServerWithInterceptors, { ServerInterceptor, ServerInterceptingCall } from 'grpc-node-server-interceptors'; const interceptors: ServerInterceptor[] = [ (call, nextCall) => { return new ServerInterceptingCall(nextCall(call), { onReceiveMessage: (message, next) => { console.log('Received message:', message); next(message); }, onSendMessage: (response, next) => { if (response.status !== GrpcStatus.OK) { console.error('Error response:', response); } next(response); }, }); }, ]; const server = new GrpcServerWithInterceptors({ interceptors }); server.addService(serviceDefinition, handlers); server.bindAsync('0.0.0.0:50051', Grpc.ServerCredentials.createInsecure(), (err, port) => { if (err) throw err; server.start(); });
Debug
Known issues
gotchaInterceptors must be added at server creation time; cannot be added later via addService.
fix
Define all interceptors in the constructor options.
affects: *
gotchaDefault export is the class, not an object. Using const { GrpcServerWithInterceptors } = require(...) will result in undefined.
fix
Use default import or require('grpc-node-server-interceptors').default (if using CommonJS with esModuleInterop).
affects: *
deprecatedThis library does not support grpc package (the native one); it only works with @grpc/grpc-js.
fix
Ensure you are using @grpc/grpc-js, not grpc.
affects: *
Errors
Common errors & fixes
TypeError: ServerInterceptingCall is not a constructor
Using destructured require instead of proper import.
fix
Use import { ServerInterceptingCall } from 'grpc-node-server-interceptors' or const { ServerInterceptingCall } = require('grpc-node-server-interceptors').
Error: Cannot find module 'grpc'
Missing peer dependency @grpc/grpc-js.
fix
Install @grpc/grpc-js: npm install @grpc/grpc-js
TypeError: grpc.ServerCredentials.createInsecure is not a function
Using the old grpc package instead of @grpc/grpc-js.
fix
Replace grpc with @grpc/grpc-js in imports.
Upgrade
Version history
1.0.1latest on npm
Audit
Dependencies
grpcrequiredProvides the underlying gRPC implementation and server
Agent activity
30 hits · last 30 days
node
26
Resources
grpc-node-server-interceptors — npm install grpc-node-server-interceptors · libregistry