Registry / testing / nice-grpc

nice-grpc

JSON →
library2.1.16jsnpmunverified

nice-grpc is a Node.js gRPC library that provides a modern, promise-based API with full TypeScript support. Current stable version is 2.1.16, with a release cadence of approximately every 2-3 months. It supports async-iterable server streaming, abort signals for cancellation, and integrates seamlessly with @grpc/grpc-js. Compared to grpc-js, it offers a higher-level, more ergonomic interface with automatic promise wrapping, streaming with async iterables, and built-in TypeScript types. It is designed to be compatible with all standard gRPC features including unary, server streaming, client streaming, and bidirectional streaming.

npm install nice-grpc
INSTALL
IMPORT
SIG · NICE-GRPC
N
nice-grpc
testingjavascriptv2.1.16
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.

createChannel
import { createChannel } from 'nice-grpc'
const niceGrpc = require('nice-grpc'); const { createChannel } = niceGrpc
ESM-only module; cannot use require() directly without destructuring. Since v2, only ESM is supported.
createServer
import { createServer } from 'nice-grpc'
import createServer from 'nice-grpc'
createServer is a named export, not default export. This is a common mistake.
ServerError
import { ServerError } from 'nice-grpc'
TypeScript users often forget that ServerError is also exposed as a class; it's used to throw gRPC errors with status codes.

Creates a gRPC channel and client, makes a unary RPC call with await, then closes the channel.

import { createChannel, createClient } from 'nice-grpc'; import { GreeterClient } from './generated/proto/example'; const channel = createChannel('localhost:8080'); async function main() { const client = createClient(GreeterClient, channel); const response = await client.sayHello({ name: 'World' }); console.log('Greeting:', response.message); channel.close(); } main().catch(console.error);
Debug
Known issues
breakingnice-grpc v2 is ESM-only. CommonJS require() is not supported.
fix
Migrate to ESM by setting 'type': 'module' in package.json or use .mjs extension. Alternatively, stick with v1.x (CJS).
affects: >=2.0.0
gotchaThe library depends on @grpc/grpc-js; you must install it as a peer dependency (if not already listed in package.json).
fix
Run 'npm install @grpc/grpc-js' as a dependency.
affects: >=1.0.0
deprecatedIn v2, the 'deadline' option is deprecated; use 'signal' with an AbortSignal instead.
fix
Replace deadline with AbortSignal: import { AbortController } from 'abort-controller' (if needed) and pass { signal: controller.signal }.
affects: >=2.0.0
gotchaServer streaming uses async iterables. A common mistake is to use .toArray() on the stream, which may cause memory issues for large streams.
fix
Use for-await-of to consume the stream iterable properly.
affects: >=1.0.0
breakingIn v2.0, the client methods no longer accept a callback; they always return Promises.
fix
Remove callback argument; use await or .then().
affects: 2.0.0
Errors
Common errors & fixes
Error: Cannot find module '@grpc/grpc-js'
@grpc/grpc-js is not installed as a dependency
fix
npm install @grpc/grpc-js
TypeError: (0 , nice_grpc.createClient) is not a function
Using default import instead of named import
fix
import { createClient } from 'nice-grpc'
Error [ERR_REQUIRE_ESM]: require() of ES Module not supported
Using require() with nice-grpc v2 which is ESM-only
fix
Use import syntax or switch to v1.x
Upgrade
Version history
2.1.16latest on npm
Audit
Dependencies
@grpc/grpc-jsrequiredUnderlying gRPC core implementation
abort-controlleroptionalAbort signal support in older Node.js versions
Agent activity
7 hits · last 30 days
node
6
Amazon
1
Resources
nice-grpc — npm install nice-grpc · libregistry