{"id":48057,"library":"grpc-node-server-interceptors","title":"gRPC Server Interceptors","description":"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.","status":"active","version":"1.0.1","language":"javascript","source_language":"en","source_url":"https://github.com/papajuanito/grpc-node-server-interceptors","tags":["javascript","typescript"],"install":[{"cmd":"npm install grpc-node-server-interceptors","lang":"bash","label":"npm"},{"cmd":"yarn add grpc-node-server-interceptors","lang":"bash","label":"yarn"},{"cmd":"pnpm add grpc-node-server-interceptors","lang":"bash","label":"pnpm"}],"dependencies":[{"reason":"Provides the underlying gRPC implementation and server","package":"grpc","optional":false}],"imports":[{"note":"Default export is the class. CommonJS require with destructuring will fail because the default export is not an object.","wrong":"const { GrpcServerWithInterceptors } = require('grpc-node-server-interceptors')","symbol":"GrpcServerWithInterceptors","correct":"import GrpcServerWithInterceptors from 'grpc-node-server-interceptors'"},{"note":"Named export, not default. Must use destructuring.","wrong":"import ServerInterceptor from 'grpc-node-server-interceptors'","symbol":"ServerInterceptor","correct":"import { ServerInterceptor } from 'grpc-node-server-interceptors'"},{"note":"CommonJS require is supported but TypeScript users should use ESM syntax. The class is a named export.","wrong":"const ServerInterceptingCall = require('grpc-node-server-interceptors').ServerInterceptingCall","symbol":"ServerInterceptingCall","correct":"import { ServerInterceptingCall } from 'grpc-node-server-interceptors'"}],"quickstart":{"code":"import { status as GrpcStatus } from '@grpc/grpc-js';\nimport GrpcServerWithInterceptors, { ServerInterceptor, ServerInterceptingCall } from 'grpc-node-server-interceptors';\n\nconst interceptors: ServerInterceptor[] = [\n  (call, nextCall) => {\n    return new ServerInterceptingCall(nextCall(call), {\n      onReceiveMessage: (message, next) => {\n        console.log('Received message:', message);\n        next(message);\n      },\n      onSendMessage: (response, next) => {\n        if (response.status !== GrpcStatus.OK) {\n          console.error('Error response:', response);\n        }\n        next(response);\n      },\n    });\n  },\n];\n\nconst server = new GrpcServerWithInterceptors({ interceptors });\nserver.addService(serviceDefinition, handlers);\nserver.bindAsync('0.0.0.0:50051', Grpc.ServerCredentials.createInsecure(), (err, port) => {\n  if (err) throw err;\n  server.start();\n});","lang":"typescript","description":"Creates a gRPC server with interceptors that logs incoming requests and error responses."},"warnings":[{"fix":"Define all interceptors in the constructor options.","message":"Interceptors must be added at server creation time; cannot be added later via addService.","severity":"gotcha","affected_versions":"*"},{"fix":"Use default import or require('grpc-node-server-interceptors').default (if using CommonJS with esModuleInterop).","message":"Default export is the class, not an object. Using const { GrpcServerWithInterceptors } = require(...) will result in undefined.","severity":"gotcha","affected_versions":"*"},{"fix":"Ensure you are using @grpc/grpc-js, not grpc.","message":"This library does not support grpc package (the native one); it only works with @grpc/grpc-js.","severity":"deprecated","affected_versions":"*"}],"env_vars":null,"search_vec":"'1.0.2':19 'allow':31 'authent':51 'built':12 'class':30 'client':36 'code':62 'current':15 'definit':65 'develop':32 'drop':23 'drop-in':22 'enabl':6 'error':52 'exist':60 'grpc':1,10 'grpc/grpc-js':14,27 'handl':53 'handler':61 'ideal':48 'incom':35 'intercept':34 'interceptor':3,7 'javascript':66 'librari':5 'like':46 'log':50 'middlewar':45 'middleware-lik':44 'modifi':59 'monitor':54 'outgo':39 'pattern':47 'provid':20 'replac':25 'request':37 'request/response':56 'respons':41 'server':2,11,29,40 'ship':63 'stabl':16 'support':8 'transform':57 'typescript':64,67 'use':42 'version':17 'without':58","created_at":"2026-06-07T16:54:42.372694+00:00","updated_at":"2026-06-07T16:54:42.372694+00:00","problems":[{"fix":"Use import { ServerInterceptingCall } from 'grpc-node-server-interceptors' or const { ServerInterceptingCall } = require('grpc-node-server-interceptors').","cause":"Using destructured require instead of proper import.","error":"TypeError: ServerInterceptingCall is not a constructor"},{"fix":"Install @grpc/grpc-js: npm install @grpc/grpc-js","cause":"Missing peer dependency @grpc/grpc-js.","error":"Error: Cannot find module 'grpc'"},{"fix":"Replace grpc with @grpc/grpc-js in imports.","cause":"Using the old grpc package instead of @grpc/grpc-js.","error":"TypeError: grpc.ServerCredentials.createInsecure is not a function"}],"ecosystem":"npm","meta_description":null,"install_score":null,"quickstart_score":null,"quickstart_tag":null,"pypi_latest":null,"cli_name":null,"cli_version":null,"type":"library","homepage":"https://github.com/papajuanito/grpc-node-server-interceptors","github":"https://github.com/papajuanito/grpc-node-server-interceptors","docs":null,"changelog":null,"pypi":null,"npm":"grpc-node-server-interceptors","openapi_spec":null,"status_page":null,"smithery":null,"categories":["backend","infrastructure"],"base_url":null,"auth_type":null,"provenance":{"verified_status":null,"verified_at":null,"last_verified":"2026-06-07","next_check":"2026-09-05","install_tag":null}}