Registry / testing / basic-grpc

basic-grpc

JSON →
library0.0.3jsnpmunverified

A minimal wrapper over grpc and @grpc/proto-loader for Node.js, aiming to simplify gRPC server and client setup. Version 0.0.3 is the current release with no regular release cadence noted. Unlike full-featured frameworks like gRPC-Web or NestJS gRPC, it provides a thin layer with TypeScript support, prototype service definitions, and helper functions for credentials, error handling, and server/client creation. Designed for developers who want a quick start with gRPC without managing the underlying grpc-js complexity directly.

npm install basic-grpc
INSTALL
IMPORT
SIG · BASIC-GRPC
B
basic-grpc
testingjavascriptv0.0.3
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.

createServer
✓ import { createServer } from 'basic-grpc'
✗ const { createServer } = require('basic-grpc')
ESM-only; CommonJS require may not work depending on bundler. Use import statement.
createClient
✓ import { createClient } from 'basic-grpc'
✗ const createClient = require('basic-grpc').createClient
ESM-only; CommonJS require may not work depending on bundler. Use import statement.
RPCError
✓ import { RPCError } from 'basic-grpc'
✗ const RPCError = require('basic-grpc').RPCError
ESM-only; CommonJS require may not work depending on bundler. Use import statement.
createServerCreds
✓ import { createServerCreds } from 'basic-grpc'
✗ const createServerCreds = require('basic-grpc').createServerCreds
ESM-only; CommonJS require may not work depending on bundler. Use import statement.
createClientCreds
✓ import { createClientCreds } from 'basic-grpc'
✗ const createClientCreds = require('basic-grpc').createClientCreds
ESM-only; CommonJS require may not work depending on bundler. Use import statement.
ISetup
✓ import { ISetup } from 'basic-grpc'
TypeScript only; used for typing the server setup configuration.
IProtoService
✓ import { IProtoService } from 'basic-grpc'
TypeScript only; used for typing a service definition.

Creates a gRPC server and client with a simple login service, demonstrating service definition, error handling, and client invocation.

import { createServer, createClient, RPCError, IProtoService, ISetup } from 'basic-grpc'; import { join } from 'path'; // Server setup const loginService: IProtoService<{ login: Function }> = { protoFile: 'login.proto', packageName: 'login', serviceName: 'Login', handlers: { login: async ({ username, password }: { username: string; password: string }) => { if (password === 'secret') return { token: 'abc123' }; throw new RPCError(22, 'Invalid credentials'); } } }; const serverConfig: ISetup = { protoRoot: join(__dirname, 'protos'), services: [loginService] }; const server = createServer({ gRPCSetup: serverConfig, domain: 'localhost:50051' }); server.start(); // Client setup const client = createClient<{ login: Function }>({ url: 'localhost', port: '50051', protoPath: join(__dirname, 'protos', 'login.proto'), packageName: 'login', serviceName: 'Login' }); async function main() { const result = await client.login({ username: 'user', password: 'secret' }); console.log(result.token); } main();
Debug
Known issues
gotchaPackage name 'basic-grpc' but examples use 'simple-grpc'. Ensure correct import from 'basic-grpc'.
fix
Use import { ... } from 'basic-grpc' instead of 'simple-grpc'.
affects: all
gotchaProto file path resolution: The protoRoot for server must be a directory, but protoPath for client must be the full path to the .proto file. Mixing them up causes load failure.
fix
For server: set protoRoot to directory containing .proto files. For client: set protoPath to full path including filename.
affects: all
gotchaRPCError code must be an integer >= 0. Custom codes start at 15+ per gRPC docs, but invalid codes may cause undefined behavior.
fix
Use known gRPC status codes (0-15) or custom codes > 15. See https://github.com/grpc/grpc/blob/master/doc/statuscodes.md
affects: all
deprecatedThe 'grpc' package is being phased out in favor of '@grpc/grpc-js'. basic-grpc depends on 'grpc' which may require native compilation.
fix
Consider using '@grpc/grpc-js' directly or a wrapper that supports it.
affects: >=0.0.3
Errors
Common errors & fixes
Error: Cannot find module 'grpc'
Missing dependency: 'grpc' is required but not installed (or failing to compile).
fix
Run npm install grpc. If native compilation fails, ensure build tools are installed (e.g., build-essential on Linux, windows-build-tools on Windows).
TypeError: login is not a function
Client method not correctly typed or the service definition mismatches. The createClient generic may not match the actual RPC method name.
fix
Ensure the TypeScript interface used with createClient has a property matching the RPC method name (e.g., login). Check proto file and client declaration.
Error: 20 UNIMPLEMENTED: Method not found: /login.Login/login
Service name, package name, or proto path mismatched between server and client definitions.
fix
Verify that protoFile, packageName, and serviceName in server match protoPath, packageName, and serviceName in client. Also ensure the .proto file is correctly loaded.
TypeError: grpc.loadPackageDefinition is not a function
Incompatible version of '@grpc/proto-loader'. The package expects an older API.
fix
Install '@grpc/proto-loader@0.5.x' (version 0.6.x changes API). Use npm install @grpc/proto-loader@0.5.0.
Upgrade
Version history
0.0.3latest on npm
Audit
Dependencies
grpcrequiredCore gRPC library used for server and client communication
@grpc/proto-loaderrequiredLoads .proto files and generates service definitions
Agent activity
22 hits · last 30 days
node
20
OpenAI (training)
1
Resources