Registry / devops / gnat-grpc

gnat-grpc

JSON →
library1.10.1jsnpmunverified

A simple gRPC synchronous wrapper for Node.js, version 1.10.1. It simplifies unary calls and provides a configurable client/server setup. Built on top of @grpc/grpc-js, @grpc/proto-loader, and grpc, it requires explicit peer dependency installation. Notable differentiators: sync-style async/await usage, built-in error escaping for Chinese messages, and minimal boilerplate compared to raw gRPC. Currently does not support streaming calls. Maintained by gnatservice.

npm install gnat-grpc
INSTALL
IMPORT
SIG · GNAT-GRPC
G
gnat-grpc
devopsjavascriptv1.10.1
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.

Server
import { Server } from 'gnat-grpc'
const Server = require('gnat-grpc').Server
Package is CommonJS only. Use require for Node < 12.
Client
const { Client } = require('gnat-grpc')
const Client = require('gnat-grpc')
Named export, not default export.
config
const gnatGrpc = require('gnat-grpc'); gnatGrpc.config({...})
import { config } from 'gnat-grpc'
config is a module-level function, not a named export.

Shows how to configure gnat-grpc, create a server, register a service handler, and start listening.

// Setup: install required packages // npm install @grpc/grpc-js @grpc/proto-loader grpc gnat-grpc // common-config.js const gnatGrpc = require('gnat-grpc'); const grpc = require('grpc'); const protoLoader = require('@grpc/proto-loader'); gnatGrpc.config({ grpc, protoLoader }); // server.js require('./common-config'); const { Server } = require('gnat-grpc'); async function sayHello(call) { return { message: 'Hello ' + call.request.name }; } (async () => { const server = new Server({ bindPath: '0.0.0.0:50051' }); await server.registerService( { filename: 'helloworld.proto' }, { sayHello } ); server.start(); console.log('Server running on port 50051'); })();
Debug
Known issues
breakinggnatGrpc.config() must be called exactly once before any other operations.
fix
Call config() in a separate module and require it first.
affects: >=1.0.0
gettingOnly unary RPCs are supported. Streaming (server-side, client-side, bidirectional) is not implemented.
fix
Use raw @grpc/grpc-js if you need streaming.
affects: >=1.0.0
deprecatedThe peer dependency includes both @grpc/grpc-js and grpc (legacy). Mixing versions may cause issues.
fix
Ensure both packages are installed and version constraints are met.
affects: >=1.0.0
gettingError escaping is enabled by default for Chinese messages; escapeErrorAnyway option controls this.
fix
Set escapeErrorAnyway: false in config to disable based on grpc version.
affects: >=1.0.0
Errors
Common errors & fixes
Error: gnatGrpc.config must be called before any other operations
Calling Server or Client constructor before config() is called.
fix
Ensure config() is called in a required module before using gnat-grpc exports.
Error: Cannot find module '@grpc/grpc-js'
Missing peer dependency @grpc/grpc-js.
fix
Run: npm install @grpc/grpc-js @grpc/proto-loader grpc
TypeError: server.registerService is not a function
Server instance not properly constructed or config not called.
fix
Check that config() was called and new Server({ bindPath }) is used correctly.
Upgrade
Version history
1.10.1latest on npm
Audit
Dependencies
@grpc/grpc-jsrequiredCore gRPC implementation
@grpc/proto-loaderrequiredProtobuf loading utility
grpcrequiredLegacy gRPC package required alongside new one
Agent activity
10 hits · last 30 days
node
10
Resources
gnat-grpc — npm install gnat-grpc · libregistry