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

@cortec/core

v1.16.0

Published

<description>

Readme

@cortec/core

Module Overview

The @cortec/core package provides the foundation for dependency injection, lifecycle management, and service orchestration in the Cortec ecosystem. It is responsible for loading modules, managing their dependencies, handling graceful shutdowns, and providing a context for accessing services and modules.

Key features:

  • Dependency injection via context
  • Module lifecycle management (load, dispose)
  • Centralized configuration and logging
  • Graceful shutdown on signals (SIGINT, SIGTERM)
  • Error handling for uncaught exceptions

Configuration Options

Where to put config: You can pass configuration directly when constructing the core context, or load it from your package.json or a config file.

Schema:

interface ICortecConfig {
  name: string; // Application name (required)
  version: string; // Application version (required)
  printOpenHandles?: boolean; // Print open handles on exit (for debugging, optional, default: false)
  silent?: boolean; // Suppress logging output (optional, default: false)
  loadTimeout?: number; // Timeout for loading modules in ms (optional, default: 60000)
  disposeTimeout?: number; // Timeout for disposing modules in ms (optional, default: 5000)
  // ...other fields from package.json are allowed
}

Field-by-field explanation:

  • name: The name of your application. Used for identification and reporting (required).
  • version: The version of your application (required).
  • printOpenHandles: If true, prints open handles on exit for debugging resource leaks (optional).
  • silent: If true, disables logging output (optional).
  • loadTimeout: Maximum time (ms) to wait for all modules to load before timing out (optional).
  • disposeTimeout: Maximum time (ms) to wait for all modules to dispose before timing out (optional).
  • Other fields: You may include additional fields from your package.json for convenience.

Example YAML config (if using config files):

name: 'my-app'
version: '1.0.0'
printOpenHandles: true
silent: false
loadTimeout: 60000
disposeTimeout: 5000

How config is loaded: You can pass the config object directly when constructing the core context:

const cortec = new Cortec({
  name: 'my-app',
  version: '1.0.0',
  printOpenHandles: true,
  silent: false,
  loadTimeout: 60000,
  disposeTimeout: 5000,
});

Or load from your package.json:

const pkg = require('./package.json');
const cortec = new Cortec(pkg);

If required fields (name, version) are missing, an error will be thrown at startup.

Example Usage

import Cortec from '@cortec/core';
import SomeModule from '@cortec/some-module';

const serviceConfig = {
  printOpenHandles: true,
  silent: false,
  loadTimeout: 60000,
  disposeTimeout: 5000,
};

const cortec = new Cortec(serviceConfig);

// Register modules
cortec.use(new SomeModule());

// Load all modules (calls their `load` method)
await cortec.load();

// Access a module by name
const someModule = cortec.require<SomeModule>('some-module');

// Dispose all modules gracefully (calls their `dispose` method)
await cortec.dispose(0);

API Reference

Context Methods

  • has(name: string): boolean Check if a module is registered.

  • provide<T>(name: string): T | undefined Get a module by name (returns undefined if not found).

  • require<T>(name: string): T Get a module by name (throws if not found).

  • use(module: IModule) Register a module.

  • load(): Promise<void> Load all registered modules.

  • dispose(code: number): Promise<void> Dispose all modules and exit with the given code.

Lifecycle

  • Loading: Calls load(context, logger) on each registered module.
  • Disposing: Calls dispose() on each registered module in reverse order.
  • Error Handling: Uncaught exceptions trigger disposal and logging.

Signals

  • SIGINT and SIGTERM will trigger graceful shutdown via dispose.

For more details, see the source code in src/index.ts.