gRPC Protocol Buffer Inspector

0.6.0 · abandoned · verified Sun Apr 19

grpc-inspect is a utility module for Node.js designed to parse and inspect gRPC Protocol Buffer definitions, generating a "friendlier" JavaScript object representation with helper methods. This allows developers to programmatically explore service methods, message structures, and field details loaded from `.proto` files. The current stable version, 0.6.0, was last published over seven years ago. The package is effectively abandoned, relying on the legacy `grpc` package for protobuf loading. Consequently, its utility is severely limited in modern gRPC environments and with current Node.js versions, making it unsuitable for new projects and likely problematic for existing ones that have upgraded their gRPC dependencies. Its primary differentiator was providing an easier-to-traverse descriptor object than the raw output of `grpc.load`.

Common errors

Warnings

Install

Imports

Quickstart

Demonstrates loading a protobuf definition using the deprecated `grpc` package and then using `grpc-inspect` to generate and explore an inspectable descriptor object, showcasing namespace, service, and method introspection.

const grpcInspect = require('grpc-inspect');
const grpc = require('grpc');
const path = require('path');
const fs = require('fs');

// Create a dummy .proto file for demonstration
const pbpath = path.resolve(__dirname, 'helloworld.proto');
const protoContent = `
syntax = "proto3";

package helloworld;

service Greeter {
  rpc SayHello (HelloRequest) returns (HelloReply) {}
}

message HelloRequest {
  string name = 1;
}

message HelloReply {
  string message = 1;
}`;

fs.writeFileSync(pbpath, protoContent);

try {
  // Load the protobuf definition using the deprecated 'grpc' package
  const proto = grpc.load(pbpath);

  // Inspect the loaded protobuf definition
  const descriptor = grpcInspect(proto);

  console.log('--- Namespaces ---');
  console.dir(descriptor.namespaceNames());

  console.log('\n--- Services in helloworld namespace ---');
  console.dir(descriptor.serviceNames('helloworld'));

  console.log('\n--- Greeter service methods ---');
  console.dir(descriptor.methods('Greeter'));

  console.log('\n--- Full Descriptor Object (truncated) ---');
  // console.dir(descriptor, { depth: null }); // Uncomment for full object
  console.dir(descriptor.namespaces.helloworld.messages.HelloRequest); // Example message inspection

} catch (error) {
  console.error('Error loading or inspecting proto:', error.message);
  console.error('This package uses the deprecated `grpc` module, which may cause issues with modern Node.js versions or `@grpc/grpc-js`.');
} finally {
  // Clean up the dummy proto file
  fs.unlinkSync(pbpath);
}

view raw JSON →