npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

nestjs-grpc-reflection-sb

v0.0.12

Published

A pluggable gRPC Reflection Server for the NestJS framework

Downloads

8

Readme

Description

A pluggable gRPC Reflection Server for the excellent NestJS framework.

Adding this module to your existing NestJS-based gRPC microservice will allow clients such as postman to dynamically load your API definitions from your running application rather than needing to load each proto file manually.

example of reflection working with postman

Getting Started

To get started, first install the package:

$ npm install nestjs-grpc-reflection

Then simply register the GrpcReflectionModule from the root module of your application - it takes in the same GrpcOptions that are used to create your microservice. The gRPC Reflection Server module runs within your application's existing gRPC server just as any other controller in your microservice, so loading the module will add the appropriate routes to your application.

import { GrpcReflectionModule } from 'nestjs-grpc-reflection';
...
@Module({
  imports: [GrpcReflectionModule.register(grpcClientOptions)],
  ...
})
export class AppModule {}

Finally, NestJS needs to know where the reflection proto files are so that it can serialize/deserialize its message traffic. For convenience, this can be automatically added to your GrpcOptions using the addReflectionToGrpcConfig function like so:

import { addReflectionToGrpcConfig } from 'nestjs-grpc-reflection';
...
export const grpcClientOptions: GrpcOptions = addReflectionToGrpcConfig({
  transport: Transport.GRPC,
  options: {
    package: 'sample',
    protoPath: join(__dirname, 'sample/proto/sample.proto'),
  },
});

Alternatively, these paths can be added manually by appending the REFLECTION_PACKAGE and REFLECTION_PROTO constants to the package and protoPath lists respectively.

:warning: If you are using @grpc/proto-loader's keepCase option you may experience some issues with the server reflection API. This module assumes that the microservice server is running with keepCase off (the NestJS default) and will attempt to convert back to the original case if it's on but this may not be perfect in all cases.

Local Development

This repository contains a simple example gRPC service as well as the gRPC reflection module library, so new features can be tested against that service.

$ npm install

Generating Types

This repo uses ts-proto for type generation. If any of the the reflection API proto files are changed, we'll need to regenerate the types to reflect that change. This relies on the protoc compiler, so if that's not installed already you'll need to do so first - instructions can be found on their site here.

$ npm run generate # regenerate reflection types, requires 'protoc' to be installed

Running the app

# development
$ npm run start

# watch mode
$ npm run start:dev

# production mode
$ npm run start:prod

Test

# unit tests
$ npm run test

# e2e tests
$ npm run test:e2e

# test coverage
$ npm run test:cov