{"id":48035,"library":"grpc-host-builder","title":"grpc-host-builder","description":"Lightweight configurator for building gRPC servers with interceptor support. Current stable version is 6.4.4, released under an active development cadence. This library provides a fluent builder pattern to construct gRPC servers using @grpc/grpc-js, with built-in support for loggers, interceptors, and service registration. It simplifies server setup by chaining methods like addInterceptor, addService, and useLoggersFactory, and offers async build via buildAsync. Differentiates from raw gRPC setup by providing a higher-level abstraction with minimal overhead.","status":"active","version":"6.4.4","language":"javascript","source_language":"en","source_url":"https://github.com/litichevskiydv/grpc-bay","tags":["javascript","gRPC","Host","Configurator","typescript"],"install":[{"cmd":"npm install grpc-host-builder","lang":"bash","label":"npm"},{"cmd":"yarn add grpc-host-builder","lang":"bash","label":"yarn"},{"cmd":"pnpm add grpc-host-builder","lang":"bash","label":"pnpm"}],"dependencies":[{"reason":"Peer dependency - core gRPC runtime","package":"@grpc/grpc-js","optional":false},{"reason":"Peer dependency - for server context","package":"processing-context","optional":true}],"imports":[{"note":"Named export, not default. Also accessible via require: const { GrpcHostBuilder } = require('grpc-host-builder')","wrong":"import GrpcHostBuilder from 'grpc-host-builder'","symbol":"GrpcHostBuilder","correct":"import { GrpcHostBuilder } from 'grpc-host-builder'"},{"note":"Use type import in TypeScript to avoid value-emit, as it is only a type","wrong":"import { GrpcHostBuilderOptions } from 'grpc-host-builder'","symbol":"type GrpcHostBuilderOptions","correct":"import type { GrpcHostBuilderOptions } from 'grpc-host-builder'"},{"note":"Utility function exported for custom loggers; not commonly used by all users","wrong":"","symbol":"createLogger","correct":"import { createLogger } from 'grpc-host-builder'"}],"quickstart":{"code":"import { GrpcHostBuilder } from 'grpc-host-builder';\nimport { credentials, ServerCredentials } from '@grpc/grpc-js';\n\nconst grpcBind = { credentials: ServerCredentials.createInsecure() };\nconst host = '0.0.0.0:50051';\n\nasync function main() {\n  const server = await new GrpcHostBuilder()\n    .addInterceptor(async (call, next) => {\n      console.log(`Received call for ${call.getPath()}`);\n      return next(call);\n    })\n    .addService(proto.Greeter.service, {\n      sayHello: (call) => ({ message: `Hello ${call.request.name}` })\n    })\n    .bind(grpcBind)\n    .buildAsync();\n\n  server.start();\n  console.log(`Server listening on ${host}`);\n}\n\nmain().catch(console.error);","lang":"typescript","description":"Create a gRPC server with interceptor and service registration using GrpcHostBuilder."},"warnings":[{"fix":"Await buildAsync() result. Update code from const server = new GrpcHostBuilder().buildAsync(); to const server = await new GrpcHostBuilder().buildAsync();","message":"v6.0.0 changed buildAsync to return a promise instead of the server directly. Previously it returned the server synchronously.","severity":"breaking","affected_versions":">=6.0.0"},{"fix":"Use import { GrpcHostBuilder } from 'grpc-host-builder' instead of require.","message":"Use of require('grpc-host-builder') is deprecated. Only ESM imports are supported as of v6.","severity":"deprecated","affected_versions":">=6.0.0"},{"fix":"Ensure interceptor classes implement invoke method matching expected signature.","message":"The addInterceptor method expects a class with invoke method or a function. Supplying a class without invoke will cause runtime error.","severity":"gotcha","affected_versions":"all"},{"fix":"Run npm install @grpc/grpc-js alongside grpc-host-builder.","message":"Peer dependency @grpc/grpc-js must be installed separately. Missing it leads to 'Cannot find module' errors.","severity":"gotcha","affected_versions":"all"}],"env_vars":null,"search_vec":"'6.4.4':18 'abstract':78 'activ':22 'addinterceptor':57 'addservic':58 'async':63 'build':8,64 'buildasync':66 'builder':4,30 'built':40 'built-in':39 'cadenc':24 'chain':54 'configur':6,85 'construct':33 'current':14 'develop':23 'differenti':67 'fluent':29 'grpc':2,9,34,70,83 'grpc-host-build':1 'grpc/grpc-js':37 'higher':76 'higher-level':75 'host':3,84 'interceptor':12,45 'javascript':82 'level':77 'librari':26 'lightweight':5 'like':56 'logger':44 'method':55 'minim':80 'offer':62 'overhead':81 'pattern':31 'provid':27,73 'raw':69 'registr':48 'releas':19 'server':10,35,51 'servic':47 'setup':52,71 'simplifi':50 'stabl':15 'support':13,42 'typescript':86 'use':36 'useloggersfactori':60 'version':16 'via':65","created_at":"2026-06-07T16:54:35.612856+00:00","updated_at":"2026-06-07T16:54:35.612856+00:00","problems":[{"fix":"Change import GrpcHostBuilder from 'grpc-host-builder' to import { GrpcHostBuilder } from 'grpc-host-builder'","cause":"Using default import instead of named import","error":"TypeError: grpc_host_builder_1.GrpcHostBuilder is not a constructor"},{"fix":"Run npm install @grpc/grpc-js","cause":"Missing peer dependency @grpc/grpc-js","error":"Error: Cannot find module '@grpc/grpc-js'"},{"fix":"Ensure you are calling buildAsync on a GrpcHostBuilder instance and using version >=6.0.0 that returns a promise.","cause":"Calling buildAsync on an already built server or using wrong version","error":"TypeError: server.buildAsync 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/litichevskiydv/grpc-bay/tree/main/packages/grpc-host-builder#readme","github":"https://github.com/litichevskiydv/grpc-bay","docs":null,"changelog":null,"pypi":null,"npm":"grpc-host-builder","openapi_spec":null,"status_page":null,"smithery":null,"categories":["devops"],"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}}