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

nestjs-metadata-discovery

v0.1.2

Published

<p align="center"> <a href="http://nestjs.com/" target="blank"><img src="https://nestjs.com/img/logo-small.svg" width="200" alt="Nest Logo" /></a> </p>

Downloads

15

Readme

NestJS Metadata Discovery Module

Description

A NestJS Module that simplifies the creation of services that can discover metadata from methods to be consumed by decorated handlers from other classes.

Installation

pnpm nestjs-metadata-discovery@latest

Usage

  1. Create a service that implements registerHandler. Here we have an example of a class that extends EventEmitter that listens for events and calls the handler that was registered in the Service1 class.

    @Injectable()
    export class Service1 extends EventEmitter {
      @Inject('OPTIONS')
      private options: any;
    
      // Map of handlers to the tuple of Context and Decorated Method
      private map_of_handlers = new Map<string, [any, FunctionController]>();
    
      constructor() {
        super();
        // Listen for Some Events
        this.on('SOME_EVENT', this.handleSomeEvent.bind(this));
      }
    
      // Catch all Handler
      async handleSomeEvent(...args) {
        // Get handler from map of registered handlers
        const handler = this.map_of_handlers.get(metadata_value);
        if (!handler) {
          throw new Error('Handler not found');
        }
        const [context, method] = handler;
        // Call handler in the context of the class where it was defined.
        return method.apply(context, args);
      }
    
      registerHander(
        metadata_key: string,
        metadata_value: string,
        handler: FunctionConstructor,
        instance: any
      ) {
        // Register handler to map of registered handlers
    
        this.map_of_handlers.set(metadata_value, [instance, handler]);
      }
    }
  2. Create a decorator that will be used to decorate the method that will be called when the event is emitted.

    export function Handle(some_key: string) {
      return applyDecorators(SetMetadata('EVENT_HANDLER', some_key));
    }
  3. Decorate your Service Methods with your decorator.

    @Injectable()
    export class Service2 {
      @Handle('SOME_EVENT')
      async handleSomeEvent(...args) {
        // Do something
      }
    }
  4. Use the MetadataDiscoveryModule to register your handlers.

    import { MetadataDiscoveryModule } from '@app/metadata-discovery';
    
    @Module({
      imports: [
        MetadataDiscoveryModule.forRoot(
          {
            metadata_key: 'EVENT_HANDLER', // Metadata Key to discover
            discover_controllers: true, // Discover Controllers
            discover_services: true, // Discover Services
          },
          Service1 // Service that implements `registerHandler`
        ),
        // Import other modules
      ],
      providers: [
        // Import other providers,
        Service2,
      ],
    })
    export class AppModule {}
  5. When the app runs and SOME_EVENTS events are emitted, the Service1 will call the methods decorated in Service2 .