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

@dunx/core

v3.10.6

Published

DI container, modules, lifecycle and the injectable Logger contract for the dunx framework

Readme

@dunx/core

The dependency injection container, modules, lifecycle, configuration, and the Logger and RequestContext contracts for dunx.

No dependencies. The other dunx packages can inject a Logger without installing a logging library.

Install

bun add @dunx/core @dunx/transform

Usage

Constructor injection needs no decorators:

import { AppFactory, Module } from '@dunx/core';

export class UsersService {
  constructor(private readonly repo: UsersRepository) {}
}

@Module({
  providers: [UsersRepository, UsersService],
  exports: [UsersService], // absent means nothing is exported
})
export class UsersModule {}

const app = await AppFactory.create(AppModule);

You do not need @Injectable, @Inject, reflect-metadata or experimentalDecorators. @dunx/transform reads each constructor's parameter types when the file loads. Turn it on in bunfig.toml, once for the app and once for tests:

preload = ["@dunx/transform/preload"]

[test]
preload = ["@dunx/transform/preload"]

What is here

| Area | What it covers | Guide | | ------------- | ------------------------------------------------------------ | ------------------------------------------------------ | | Providers | Constructor injection, provide(), token(), inject() | Providers | | Modules | Scoping, imports, exports, global, forRoot | Modules | | Lifecycle | onInit, onBeforeShutdown, onShutdown, signal handlers | Lifecycle | | Configuration | ConfigModule.forRoot, a validate function or a schema | Configuration | | Logging | The Logger contract and ConsoleLogger | Logging | | Events | EventBus, AppEvent, @OnEvent, EventRegistry | Events | | Stats | Durations, Counter, Gauge, RuntimeStats, EventLoopLag | Metrics | | Resilience | ResiliencePolicy, timeout, retry, backoff, jitter, fallback, CircuitBreaker, Bulkhead | Resilience | | Tracing | The Tracer contract, NoopTracer, and OtelModule on /otel | Tracing |

Subpaths

| Subpath | Contains | | ----------------- | ------------------------------------------------------------------------- | | @dunx/core | Everything above. Never imports @opentelemetry/api | | @dunx/core/otel | OtelModule and OtelTracer, on the optional peer @opentelemetry/api |

bun add @opentelemetry/api   # only for @dunx/core/otel, ^1.4.0

@opentelemetry/api is a peer dependency so that your SDK and dunx use the same copy. With two copies installed, spans can go missing without an error. dunx does not include an SDK or an exporter: register your own before calling create.

Notes

  • Each module is its own scope. A module can use what it declares and what the modules it imports export. List what other modules may use in exports; leave exports out and nothing is shared. global: true makes a module's exports available everywhere.

  • If a constructor parameter's type does not exist at runtime (an interface, a primitive, a union or a type-only import), boot fails with an error naming that parameter. You never get a silent undefined. A parameter with a default value keeps its default.

  • Logger, RequestContext and Tracer can always be injected. The defaults are ConsoleLogger, AsyncRequestContext (on AsyncLocalStorage) and NoopTracer, and a module that binds one replaces the default. @dunx/http relies on this to log requests in an app with no logging module.

  • ConsoleLogger collects info and lower into one write per event-loop turn. warn and higher are written at once, along with anything waiting before them.

  • The stats classes use only node:perf_hooks and process, so the package still has no dependencies.

  • Durations fixes four problems with Node's native histogram:

    | Native histogram | Durations | | ----------------------------------------------------------------- | --------------------------------- | | record(0) throws ERR_OUT_OF_RANGE | A value under 1 is recorded as 1 | | An empty histogram reports min 9223372036854776000, mean NaN | An empty snapshot is { count: 0 } | | percentiles is a Map of bigint, which serialises to {} | percentile(n) returns a number | | mean costs 42.2 us | No mean |

License

MIT