Registry / devops / grpc-host-builder

grpc-host-builder

JSON →
library6.4.4jsnpmunverified

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.

npm install grpc-host-builder
INSTALL
IMPORT
SIG · GRPC-HOST-BUILDER
G
grpc-host-builder
devopsjavascriptv6.4.4
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.

GrpcHostBuilder
import { GrpcHostBuilder } from 'grpc-host-builder'
import GrpcHostBuilder from 'grpc-host-builder'
Named export, not default. Also accessible via require: const { GrpcHostBuilder } = require('grpc-host-builder')
type GrpcHostBuilderOptions
import type { GrpcHostBuilderOptions } from 'grpc-host-builder'
import { GrpcHostBuilderOptions } from 'grpc-host-builder'
Use type import in TypeScript to avoid value-emit, as it is only a type
createLogger
import { createLogger } from 'grpc-host-builder'
Utility function exported for custom loggers; not commonly used by all users

Create a gRPC server with interceptor and service registration using GrpcHostBuilder.

import { GrpcHostBuilder } from 'grpc-host-builder'; import { credentials, ServerCredentials } from '@grpc/grpc-js'; const grpcBind = { credentials: ServerCredentials.createInsecure() }; const host = '0.0.0.0:50051'; async function main() { const server = await new GrpcHostBuilder() .addInterceptor(async (call, next) => { console.log(`Received call for ${call.getPath()}`); return next(call); }) .addService(proto.Greeter.service, { sayHello: (call) => ({ message: `Hello ${call.request.name}` }) }) .bind(grpcBind) .buildAsync(); server.start(); console.log(`Server listening on ${host}`); } main().catch(console.error);
Debug
Known issues
breakingv6.0.0 changed buildAsync to return a promise instead of the server directly. Previously it returned the server synchronously.
fix
Await buildAsync() result. Update code from const server = new GrpcHostBuilder().buildAsync(); to const server = await new GrpcHostBuilder().buildAsync();
affects: >=6.0.0
deprecatedUse of require('grpc-host-builder') is deprecated. Only ESM imports are supported as of v6.
fix
Use import { GrpcHostBuilder } from 'grpc-host-builder' instead of require.
affects: >=6.0.0
gotchaThe addInterceptor method expects a class with invoke method or a function. Supplying a class without invoke will cause runtime error.
fix
Ensure interceptor classes implement invoke method matching expected signature.
affects: all
gotchaPeer dependency @grpc/grpc-js must be installed separately. Missing it leads to 'Cannot find module' errors.
fix
Run npm install @grpc/grpc-js alongside grpc-host-builder.
affects: all
Errors
Common errors & fixes
TypeError: grpc_host_builder_1.GrpcHostBuilder is not a constructor
Using default import instead of named import
fix
Change import GrpcHostBuilder from 'grpc-host-builder' to import { GrpcHostBuilder } from 'grpc-host-builder'
Error: Cannot find module '@grpc/grpc-js'
Missing peer dependency @grpc/grpc-js
fix
Run npm install @grpc/grpc-js
TypeError: server.buildAsync is not a function
Calling buildAsync on an already built server or using wrong version
fix
Ensure you are calling buildAsync on a GrpcHostBuilder instance and using version >=6.0.0 that returns a promise.
Upgrade
Version history
6.4.4latest on npm
Audit
Dependencies
@grpc/grpc-jsrequiredPeer dependency - core gRPC runtime
processing-contextoptionalPeer dependency - for server context
Agent activity
6 hits · last 30 days
node
6
Resources
grpc-host-builder — npm install grpc-host-builder · libregistry