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

@camcima/nestjs-memory-microservices

v0.2.0

Published

In-memory NestJS microservice transport for testing — full pipeline, zero broker

Readme

CI CodeQL codecov npm version License: MIT TypeScript Node.js

An in-memory NestJS microservice transport for testing. Full pipeline, zero broker.

The Problem

Testing @nestjs/microservices handlers is painful:

| Approach | Guards | Pipes | Interceptors | Filters | Broker needed? | |----------|--------|-------|--------------|---------|----------------| | Direct method call | No | No | No | No | No | | ClientProxy + emulator | Yes | Yes | Yes | Yes | Yes | | MemoryServer | Yes | Yes | Yes | Yes | No |

  • Direct method calls bypass the entire NestJS pipeline -- you're testing a function, not your microservice.
  • Real brokers / emulators are slow, require infrastructure, and return async fire-and-forget results you can't inspect.
  • There's no supertest equivalent for microservices.

How It Works

MemoryServer is a custom transport strategy that extends @nestjs/microservices' Server base class. The Server class stores handler functions that are already wrapped with the full NestJS pipeline (guards, interceptors, pipes, exception filters). MemoryServer simply invokes them in-process -- no network, no broker, no emulator.

Your handlers use standard NestJS decorators (@EventPattern, @MessagePattern, @Payload, @Ctx). Zero vendor lock-in.

Installation

npm install --save-dev @camcima/nestjs-memory-microservices

Peer dependencies (you probably already have these):

npm install @nestjs/common @nestjs/core @nestjs/microservices rxjs reflect-metadata

Quick Start

import { Controller } from '@nestjs/common';
import { EventPattern, MessagePattern, Payload } from '@nestjs/microservices';

@Controller()
export class OrdersController {
  @EventPattern('order.created')
  handleOrderCreated(@Payload() data: { orderId: string; amount: number }) {
    console.log(`Order ${data.orderId} created for $${data.amount}`);
  }

  @MessagePattern('get.order')
  getOrder(@Payload() data: { id: string }) {
    return { orderId: data.id, status: 'shipped' };
  }
}
import { Test } from '@nestjs/testing';
import { MemoryServer } from '@camcima/nestjs-memory-microservices';
import { OrdersController } from './orders.controller';

describe('OrdersController', () => {
  let server: MemoryServer;

  beforeAll(async () => {
    server = new MemoryServer();
    const module = await Test.createTestingModule({
      controllers: [OrdersController],
    }).compile();
    const app = module.createNestMicroservice({ strategy: server });
    await app.init();
  });

  it('handles events', async () => {
    await server.emit('order.created', { orderId: '123', amount: 49.99 });
  });

  it('handles request-response', async () => {
    const result = await server.request('get.order', { id: 'order-42' });
    expect(result).toEqual({ orderId: 'order-42', status: 'shipped' });
  });
});

Or use the convenience helper:

import { createTestingMicroservice } from '@camcima/nestjs-memory-microservices';

const { app, server } = await createTestingMicroservice({
  controllers: [OrdersController],
});

await server.emit('order.created', { orderId: '123', amount: 49.99 });
const result = await server.request('get.order', { id: 'order-42' });

await app.close();

Documentation

Production Usage

In production, use your real transport. The handler code is identical -- only the bootstrap changes:

// main.ts -- production
const app = await NestFactory.createMicroservice(AppModule, {
  transport: Transport.RMQ,
  options: { urls: ['amqp://localhost:5672'], queue: 'orders' },
});

// test -- swap to MemoryServer, no broker needed
const server = new MemoryServer();
const app = module.createNestMicroservice({ strategy: server });

Compatibility

| Dependency | Version | |-----------|---------| | Node.js | >= 18.0.0 | | NestJS | ^10.0.0 || ^11.0.0 | | TypeScript | >= 5.0 | | RxJS | ^7.0.0 |

Security

CI

| Tool | Purpose | Trigger | |------|---------|---------| | CodeQL | Static analysis for security vulnerabilities | Push/PR to main, weekly schedule | | OSV-Scanner | Dependency vulnerability scanning (production deps only) | Push/PR to main | | Dependabot | Automated dependency and GitHub Actions updates | Weekly |

Local (via Lefthook)

Gitleaks runs automatically on every commit (pre-commit) to catch secrets before they reach the remote.

Prerequisites: install Gitleaks.

Manual commands

# Dependency audit (production deps only)
npm run security:audit

# Secret scanning
npm run security:secrets

Optional: Semgrep

Semgrep can be used for additional local code-security scanning. It is not included in the default hooks to keep the local workflow lightweight, but can be run on demand:

# Install: https://semgrep.dev/docs/getting-started/
semgrep scan --config auto src/

License

MIT