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 🙏

© 2026 – Pkg Stats / Ryan Hefner

@funduck/connectrpc-fastify-nestjs

v1.0.11

Published

Wrapper for official @connectrpc/connect and fastify integrated into Nestjs. Simplifies configuration, type safe binding to controller, simplifies use of middlewares.

Readme

Connectrpc Fastify Wrapper For Nestjs

Repo on github
Package on npm
Related base repo without Nestjs

Description

This package allows to add Connectrpc into Nestjs project using the Fastify server.

If you are comfortable with HTTP/1 only and want a compact, ready-to-use setup, this repository is for you.

It simplifies the binding of controllers and middlewares.

It uses my another package Connectrpc Fastify Wrapper.

Features

This library allows you to:

  • Use only HTTP/1 transport
  • Perform RPC with simple request and response messages
  • Perform RPC with streaming responses
  • Perform RPC with streaming requests
  • Use middlewares
  • Use interceptors

Bidirectional streaming RPC is currently out of scope because it requires HTTP/2, which is unstable on public networks. In practice, HTTP/1 provides more consistent performance.

How To Use

You can check out the test/demo directory for a complete example of server and client integration using NestJS and Fastify. Start reading from test/demo/app.module.ts.

Except the bootstrap instructions are pretty much the same as in Connectrpc Fastify Wrapper.

Controllers

Controller must implement the service interface (not all methods) and register itself using ConnectRPC.registerController:

@Injectable()
export class ElizaController implements Service<typeof ElizaService> {
  @Inject(Logger)
  private logger: Logger;

  constructor() {
    ConnectRPC.registerController(this, ElizaService);
  }

  async say(
    request: SayRequest,
  ) {
    return {
      sentence: `You said: ${request.sentence}`,
    };
  }

  // ... Other methods are optional
}

Middlewares

Middleware must implement Middleware interface and register itself using ConnectRPC.registerMiddleware:

@Injectable()
export class TestMiddleware1 implements Middleware {
  @Inject(Logger)
  private logger: Logger;

  constructor() {
    ConnectRPC.registerMiddleware(this);
  }

  use(req: FastifyRequest['raw'], res: FastifyReply['raw'], next: () => void) {
    next();
  }
}

Interceptors

Interceptor must implement Interceptor interface and register itself using ConnectRPC.registerInterceptor:

@Injectable()
export class TestInterceptor1 implements Interceptor {
  @Inject(Logger)
  private logger: Logger;

  constructor() {
    ConnectRPC.registerInterceptor(this);
  }

  use(next: AnyFn): AnyFn {
    return async (req) => {
      this.logger.log(`TestInterceptor1 invoked`);
      return await next(req);
    };
  }
}

Module Setup

Configure your NestJS module to use ConnectRPCModule.forRoot and register middlewares and interceptors as providers if necessary:

@Module({
  imports: [
    // Configure ConnectRPCModule
    ConnectRPCModule.forRoot({
      logger: new Logger('ConnectRPC', { timestamp: true }),
      middlewares: [
        middlewareConfig(TestMiddleware1),
        middlewareConfig(TestMiddleware2, ElizaService),
        middlewareConfig(TestMiddleware3, ElizaService, ['say']),
      ],
      interceptors: [
        interceptorConfig(TestInterceptor1),
        interceptorConfig(TestInterceptor2, ElizaService),
        interceptorConfig(TestInterceptor3, ElizaService, ['say']),
      ],
    }),
  ],
  providers: [
    Logger,

    // Controllers are provided here instead of `controllers` array
    ElizaController, 

    // Middlewares specific for ConnectRPC are provided here
    TestMiddleware1, 
    TestMiddleware2,

    // Middlewares that are applied via `consumer.apply()` should NOT be provided here
    // Do not instantiate TestMiddleware3 twice!

    // Interceptors specific for ConnectRPC are provided here
    TestInterceptor1,
    TestInterceptor2,
    TestInterceptor3,
  ],
})
export class AppModule implements NestModule {
  configure(consumer: MiddlewareConsumer) {
    consumer.apply(TestMiddleware3).forRoutes('*'); // TestMiddleware3 is instantiated here!
  }
}

Server Bootstrap

Just add the call to ConnectRPCModule after creating the app:

export async function bootstrap() {
  const app = await NestFactory.create<NestFastifyApplication>(
    AppModule,
    new FastifyAdapter(),
  );

  // After the app is created, register the ConnectRPCModule
  await app.get(ConnectRPCModule).registerPlugin();

  await app.listen(3000);
}

Strict Mode

If strict mode is enabled the library will cause process to exit on errors such as missing middleware or interceptor instances.
By default, strict mode is disabled to allow more flexibility during development.

To enable it call ConnectRPC.setStrictMode(true) before registering any middlewares or interceptors.
To check it read ConnectRPC.isStrictMode property.

More examples

See test/demo and examples directories for more examples.

Feedback

Please use Discussions or email me.