Registry / devops / better-grpc

better-grpc

JSON →
library0.3.2jsnpmunverified

better-grpc is a TypeScript-first gRPC library (version 0.3.2) that eliminates the need for .proto files and code generation, offering full type safety and autocompletion. It enables bidirectional communication where client and server can call each other's functions as if local. Released under MIT, it supports Node.js >=18 and TypeScript ^5. Simpler than raw gRPC-js but less mature than tRPC; no streaming support yet (only simple RPCs).

npm install better-grpc
INSTALL
IMPORT
SIG · BETTER-GRPC
B
better-grpc
devopsjavascriptv0.3.2
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.

Service
import { Service } from 'better-grpc'
const Service = require('better-grpc').Service
ESM-only package; CommonJS require() will not work.
createGrpcServer
import { createGrpcServer } from 'better-grpc'
import { createGrpcServer } from 'better-grpc/server'
All exports are from the main entry point; no subpath exports.
client
import { client } from 'better-grpc'
import { client } from 'better-grpc/client'
client is a helper function for defining client-side methods.

Defines a simple service, implements server and client halves, starts server and client, makes a remote call, and logs the result.

import { Service, server, createGrpcServer, createGrpcClient } from 'better-grpc'; abstract class MyService extends Service('MyService') { sayHello = server<(name: string) => string>(); } const myServiceImpl = MyService.Server({ async sayHello(name: string) { return `Hello, ${name}!`; } }); const clientImpl = MyService.Client({}); const server = await createGrpcServer(50051, myServiceImpl); const client = await createGrpcClient('localhost:50051', clientImpl); const result = await client.client.sayHello('World'); console.log(result); // "Hello, World!" server.close();
Debug
Known issues
deprecatedThe helper function 'client' has been deprecated in favor of 'client' export from 'better-grpc'? Actually not deprecated, but caution: 'client' is a reserved word in strict mode.
fix
Use 'client' as a named function, but avoid naming your variables 'client' to prevent confusion.
affects: >=0.1.0
gotchaService('MyService') returns a class; the string argument must be unique per service.
fix
Provide a unique string name for each Service definition.
affects: >=0.1.0
breakingIn version 0.2.0, the signature of createGrpcServer changed from (port, impl) to (port, impl, options?).
fix
Update calls to include options object if needed, or omit for default.
affects: >=0.2.0
gotchaClient-side method implementations must be defined in the Client initializer, not in the Service class.
fix
Implement client methods in the MyService.Client({...}) object.
affects: >=0.1.0
deprecatedThe 'createGrpcClient' third parameter (credentials) changed from string to object in v0.3.0.
fix
Use 'ssl', 'insecure', or an options object as the second argument (before clientImpl).
affects: >=0.3.0
Errors
Common errors & fixes
TypeError: Service is not a constructor
Service('MyService') returns a class, but forgetting to call it with a string argument.
fix
Ensure you use Service('MyService') with parentheses: class MyService extends Service('MyService') {}
Error: [better-grpc] Channel credentials must be a ChannelCredentials object
Passing invalid credentials type to createGrpcClient (e.g., a number).
fix
Use 'ssl', 'insecure', or an object with gRPC channel options: createGrpcClient(address, creds?, impl)
TypeError: client.client is undefined
Forgetting to pass client implementation to createGrpcClient or incorrect destructuring.
fix
Ensure createGrpcClient is called with a client implementation object: createGrpcClient(address, impl)
Upgrade
Version history
0.3.2latest on npm
Audit
Dependencies
typescriptoptionalpeer dependency for type generation
Agent activity
7 hits · last 30 days
node
6
Resources
better-grpc — npm install better-grpc · libregistry