Registry /
backend / grpc-node-server-interceptors
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();
});
Errors
Common errors & fixes
TypeError: ServerInterceptingCall is not a constructor
Using destructured require instead of proper import.
fixUse 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.
fixInstall @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.
fixReplace grpc with @grpc/grpc-js in imports.
Audit
Dependencies
grpcrequiredProvides the underlying gRPC implementation and server