{"id":48055,"library":"grpc-node-demo","title":"grpc-node-demo","description":"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.","status":"active","version":"1.3.0","language":"javascript","source_language":"en","source_url":"https://github.com/huanhunmao/grpc-node-demo","tags":["javascript","grpc","node","demo","马克付","huanhunmao"],"install":[{"cmd":"npm install grpc-node-demo","lang":"bash","label":"npm"},{"cmd":"yarn add grpc-node-demo","lang":"bash","label":"yarn"},{"cmd":"pnpm add grpc-node-demo","lang":"bash","label":"pnpm"}],"dependencies":[{"reason":"Core gRPC implementation for Node.js.","package":"grpc","optional":false},{"reason":"Loads .proto files for gRPC service definitions.","package":"@grpc/proto-loader","optional":false}],"imports":[{"note":"CommonJS require is still widely used with grpc package, but ESM import is available. Ensure your Node version supports ESM (>=12) if using import.","wrong":"const grpc = require('grpc');","symbol":"grpc","correct":"import grpc from 'grpc';"},{"note":"The default export is a function; named exports exist but are not the primary API.","wrong":"import { loadSync } from '@grpc/proto-loader';","symbol":"protoLoader","correct":"import protoLoader from '@grpc/proto-loader';"},{"note":"You can import both default and named, but the default is the same function. Best to use named imports for clarity.","wrong":"import protoLoader, { loadSync } from '@grpc/proto-loader';","symbol":"loadSync","correct":"import { loadSync } from '@grpc/proto-loader';"}],"quickstart":{"code":"// server.js\nimport grpc from 'grpc';\nimport protoLoader from '@grpc/proto-loader';\n\nconst packageDefinition = protoLoader.loadSync('helloworld.proto', {\n  keepCase: true,\n  longs: String,\n  enums: String,\n  defaults: true,\n  oneofs: true\n});\nconst helloProto = grpc.loadPackageDefinition(packageDefinition).helloworld;\n\nfunction sayHello(call, callback) {\n  callback(null, { message: 'Hello ' + call.request.name });\n}\n\nconst server = new grpc.Server();\nserver.addService(helloProto.Greeter.service, { sayHello: sayHello });\nserver.bind('0.0.0.0:50051', grpc.ServerCredentials.createInsecure());\nserver.start();\nconsole.log('Server running on port 50051');\n\n// client.js\nimport grpc from 'grpc';\nimport protoLoader from '@grpc/proto-loader';\n\nconst packageDefinition = protoLoader.loadSync('helloworld.proto', {\n  keepCase: true,\n  longs: String,\n  enums: String,\n  defaults: true,\n  oneofs: true\n});\nconst helloProto = grpc.loadPackageDefinition(packageDefinition).helloworld;\n\nconst client = new helloProto.Greeter('localhost:50051', grpc.credentials.createInsecure());\nclient.sayHello({ name: 'World' }, function(err, response) {\n  console.log('Greeting:', response.message);\n});","lang":"javascript","description":"Sets up a basic gRPC server with a single RPC method (sayHello) and a corresponding client that calls it."},"warnings":[{"fix":"Replace `grpc` with `@grpc/grpc-js` and update imports accordingly: import grpc from '@grpc/grpc-js';","message":"The `grpc` package is deprecated in favor of `@grpc/grpc-js`.","severity":"deprecated","affected_versions":">=0.0.0"},{"fix":"Use a process manager like nodemon for auto-restart during development.","message":"If you modify server.js, you must restart the server.","severity":"gotcha","affected_versions":">=0.0.0"},{"fix":"Check port availability with `lsof -i :50051` or change the port in code.","message":"Ensure port 50051 is not occupied before starting the server.","severity":"gotcha","affected_versions":">=0.0.0"}],"env_vars":null,"search_vec":"'1.3.0':28 'abstract':56 'approach':67 'bare':65 'bare-bon':64 'basic':31 'bone':66 'call':38 'client':18 'concept':46 'demo':4,84 'demonstr':9 'emphas':48 'error':59 'exampl':7 'grpc':2,15,23,45,82 'grpc-node-demo':1 'grpc/proto-loader':25 'handl':60 'huanhunmao':86 'intend':39 'javascript':81 'layer':57 'minim':6 'node':3,83 'node.js':20 'notabl':61 'packag':26 'product':52,73 'production-readi':51 'project':8 'provid':29 'quickstart':42 'readi':53 'recent':80 'rpc':37 'seen':78 'server':16 'set':12 'setup':33 'simplic':49 'singl':36 'suitabl':71 'understand':44 'updat':79 'use':21,74 'version':27 'work':32 '马克付':85","created_at":"2026-06-07T16:54:41.517047+00:00","updated_at":"2026-06-07T16:54:41.517047+00:00","problems":[{"fix":"Run: npm install grpc @grpc/proto-loader","cause":"The npm package `grpc` not installed.","error":"Error: Cannot find module 'grpc'"},{"fix":"Verify server is running and listen address is correct (e.g., 'localhost:50051').","cause":"Client cannot reach server; often due to incorrect address or server not running.","error":"Error: 14 UNAVAILABLE: DNS resolution failed"}],"ecosystem":"npm","meta_description":null,"install_score":null,"quickstart_score":null,"quickstart_tag":null,"pypi_latest":null,"cli_name":null,"cli_version":null,"type":"library","homepage":"https://github.com/huanhunmao","github":"https://github.com/huanhunmao/grpc-node-demo","docs":null,"changelog":null,"pypi":null,"npm":"grpc-node-demo","openapi_spec":null,"status_page":null,"smithery":null,"categories":["testing"],"base_url":null,"auth_type":null,"provenance":{"verified_status":null,"verified_at":null,"last_verified":"2026-06-07","next_check":"2026-09-05","install_tag":null}}