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 🙏

© 2025 – Pkg Stats / Ryan Hefner

@golevelup/nestjs-discovery

v6.1.1

Published

A Badass NestJS module for querying your app's controllers, providers and handlers

Readme

Discovery

This module provides access to the DiscoveryService which can be used to query the various modules, providers, controllers and handlers that make up your NestJS application.

Getting Started

::: code-group

npm install ---save @golevelup/nestjs-discovery
yarn add @golevelup/nestjs-discovery
pnpm add @golevelup/nestjs-discovery

:::

Import

Import and add DiscoveryModule to the imports section of the module you wish to implement Discovery features in. It's common to inject it directly into consuming Module's contructor so that it can be used during the onModuleInit lifecycle hook at application startup.

import { DiscoveryModule } from '@golevelup/nestjs-discovery';
import { Module } from '@nestjs/common';

@Module({
  imports: [DiscoveryModule],
})
export class ExampleModule implements OnModuleInit {
  constructor(private readonly discover: DiscoveryService) {}

  public async onModuleInit() {
    // const providers = await this.discover.providersWithMetaAtKey<number>('metaKey')
  }
}

Discover

The DiscoveryService exposes several different querying patterns for your app's components that are well documented with comments. This will also provide intellisense for querying in a TypeScript compatible IDE.

In the case of querying for providers or controllers, the service returns the following interfaces:

export interface DiscoveredModule {
  name: string;
  instance: {};
  injectType?: Type<{}>;
  dependencyType: Type<{}>;
}

export interface DiscoveredClass extends DiscoveredModule {
  parentModule: DiscoveredModule;
}

This gives access to the (singleton) instance of the matching provider or controller created by the NestJS Dependency Injection container.

The injectType can contain the constructor function of the provider token if it is provided as an @Injectable class. In the case of custom providers, this value will either contain the type of the factory function that created the dependency, or undefined if a value was directly provided with useValue.

The dependencyType is a shortcut to retrieve the constructor function of the actual provided dependency itself. For @Injectable providers/controllers this will simply be the decorated class but for dyanmic providers it will return the constructor function of whatever dependency was actually returned from useValue or useFactory.

It also provides the string based name for convenience. A DiscoveredClass contains a parentModule which provides the same set of information for the @Module class that the dependency was discovered in.

When querying for methods on providers or controllers the following interface is returned:

export interface DiscoveredMethod {
  handler: (...args: any[]) => any;
  methodName: string;
  parentClass: DiscoveredClass;
}

This gives access to the handler which is the actual class method implementation as well as the ability to navigate back up the dependency tree with the attached parentClass.

When specifically querying for components in the context of looking for decorator metadata, the ...WithMetaAtKey<T> service methods return the types above along with the metadata that was discovered.

export interface DiscoveredMethodWithMeta<T> {
  discoveredMethod: DiscoveredMethod;
  meta: T;
}

export interface DiscoveredClassWithMeta<T> {
  discoveredClass: DiscoveredClass;
  meta: T;
}

Example

Assuming you were using a custom decorator in your application that attached metadata at a key called exampleKey:

const ExampleDecorator = (meta: string) => SetMetadata('exampleKey', meta);

Find all controller methods that have been decorated with @ExampleDecorator and retrieve the value they set for meta:

const exampleMethodsMeta =
  await this.discover.controllerMethodsWithMetaAtKey<string>('exampleKey');