Registry / testing / grpc-node-demo

grpc-node-demo

JSON →
library1.3.0jsnpmunverified

A minimal example project demonstrating how to set up a gRPC server and client in Node.js using the `grpc` and `@grpc/proto-loader` packages. Version 1.3.0 provides a basic working setup with a single RPC call, intended as a quickstart for understanding gRPC concepts. It emphasizes simplicity over production-readiness, with no abstraction layers or error handling. Notable for its bare-bones approach, it is not suitable for production use and has not seen updates recently.

npm install grpc-node-demo
INSTALL
IMPORT
SIG · GRPC-NODE-DEMO
G
grpc-node-demo
testingjavascriptv1.3.0
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.

grpc
import grpc from 'grpc';
const grpc = require('grpc');
CommonJS require is still widely used with grpc package, but ESM import is available. Ensure your Node version supports ESM (>=12) if using import.
protoLoader
import protoLoader from '@grpc/proto-loader';
import { loadSync } from '@grpc/proto-loader';
The default export is a function; named exports exist but are not the primary API.
loadSync
import { loadSync } from '@grpc/proto-loader';
import protoLoader, { loadSync } from '@grpc/proto-loader';
You can import both default and named, but the default is the same function. Best to use named imports for clarity.

Sets up a basic gRPC server with a single RPC method (sayHello) and a corresponding client that calls it.

// server.js import grpc from 'grpc'; import protoLoader from '@grpc/proto-loader'; const packageDefinition = protoLoader.loadSync('helloworld.proto', { keepCase: true, longs: String, enums: String, defaults: true, oneofs: true }); const helloProto = grpc.loadPackageDefinition(packageDefinition).helloworld; function sayHello(call, callback) { callback(null, { message: 'Hello ' + call.request.name }); } const server = new grpc.Server(); server.addService(helloProto.Greeter.service, { sayHello: sayHello }); server.bind('0.0.0.0:50051', grpc.ServerCredentials.createInsecure()); server.start(); console.log('Server running on port 50051'); // client.js import grpc from 'grpc'; import protoLoader from '@grpc/proto-loader'; const packageDefinition = protoLoader.loadSync('helloworld.proto', { keepCase: true, longs: String, enums: String, defaults: true, oneofs: true }); const helloProto = grpc.loadPackageDefinition(packageDefinition).helloworld; const client = new helloProto.Greeter('localhost:50051', grpc.credentials.createInsecure()); client.sayHello({ name: 'World' }, function(err, response) { console.log('Greeting:', response.message); });
Debug
Known issues
deprecatedThe `grpc` package is deprecated in favor of `@grpc/grpc-js`.
fix
Replace `grpc` with `@grpc/grpc-js` and update imports accordingly: import grpc from '@grpc/grpc-js';
affects: >=0.0.0
gotchaIf you modify server.js, you must restart the server.
fix
Use a process manager like nodemon for auto-restart during development.
affects: >=0.0.0
gotchaEnsure port 50051 is not occupied before starting the server.
fix
Check port availability with `lsof -i :50051` or change the port in code.
affects: >=0.0.0
Errors
Common errors & fixes
Error: Cannot find module 'grpc'
The npm package `grpc` not installed.
fix
Run: npm install grpc @grpc/proto-loader
Error: 14 UNAVAILABLE: DNS resolution failed
Client cannot reach server; often due to incorrect address or server not running.
fix
Verify server is running and listen address is correct (e.g., 'localhost:50051').
Upgrade
Version history
1.3.0latest on npm
Audit
Dependencies
grpcrequiredCore gRPC implementation for Node.js.
@grpc/proto-loaderrequiredLoads .proto files for gRPC service definitions.
Agent activity
14 hits · last 30 days
node
12
Resources
grpc-node-demo — npm install grpc-node-demo · libregistry