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

@dynamic-mock-server/core

v0.1.0-beta

Published

Core engine for Dynamic Mock Server — orchestrates server lifecycle, plugin system, and admin API

Downloads

77

Readme

@dynamic-mock-server/core

Core orchestrator for the Dynamic Mock Server

The main package that coordinates all components of the mock server including server initialization, configuration management, plugin system, and lifecycle orchestration.

Features

  • 🎯 Central Orchestration: Manages all core systems (server, config, mocks, plugins)
  • 🔌 Plugin System: Extensible architecture with lifecycle hooks (register, init, start, stop)
  • 🚀 Fastify Integration: High-performance HTTP server powered by Fastify
  • 🔄 Lifecycle Management: Coordinated initialization, startup, and shutdown of all components
  • 📦 Modular Design: Clean separation of concerns with dependency injection
  • 🎨 Core API: Unified interface for plugins to access core functionality

Installation

pnpm add @dynamic-mock-server/core

Quick Start

Basic Usage

import { Core } from "@dynamic-mock-server/core";

// Create and start the server
const core = new Core();
await core.start();

// Server is now running at http://localhost:3000

With Routes and Suites

import { Core } from "@dynamic-mock-server/core";

const core = new Core();

// Add routes
core.mocksManager.addRoute({
  id: "get-users",
  url: "/api/users",
  method: "GET",
  responses: [
    {
      id: "success",
      status: 200,
      body: [{ id: 1, name: "John Doe" }],
    },
    {
      id: "error",
      status: 500,
      body: { error: "Internal Server Error" },
    },
  ],
});

// Add a suite
core.mocksManager.addSuite({
  id: "base",
  routes: {
    "get-users": "success",
  },
});

// Set active suite and start
core.mocksManager.setActiveSuite("base");
await core.start();

With Custom Logger

import { Core } from "@dynamic-mock-server/core";
import { Logger } from "@dynamic-mock-server/logger";

const customLogger = new Logger({ level: "debug" });

const core = new Core({
  logger: customLogger,
});

await core.start();

With Plugins

import { Core } from "@dynamic-mock-server/core";
import type { Plugin, CoreApi } from "@dynamic-mock-server/core";

// Define a custom plugin
class MyPlugin implements Plugin {
  static id = "my-plugin";

  constructor(
    private coreApi: CoreApi,
    private core: Core,
  ) {}

  register(coreApi: CoreApi): void {
    const logger = coreApi.logger.namespace("my-plugin");
    logger.info("Plugin registered");
  }

  async init(): Promise<void> {
    // Initialize plugin
  }

  async start(): Promise<void> {
    // Start plugin
  }

  async stop(): Promise<void> {
    // Cleanup
  }
}

// Use the plugin
const core = new Core({
  plugins: { register: [MyPlugin] },
});

await core.start();

API Reference

Core Class

The main orchestrator class that manages all components.

Constructor

constructor(options?: CoreOptions)

CoreOptions:

  • config?: Config - Custom Config instance (optional)
  • logger?: Logger | false - Custom logger instance, or false to disable logging (optional)
  • plugins?: { register?: PluginConstructor[] } - Plugin configuration object (optional)

Methods

async init(): Promise<void>

Initialize the core and all plugins. Loads configuration, initializes MocksManager, and registers plugins.

async start(): Promise<void>

Start the server and all plugins. Calls init() internally if not already initialized.

async stop(): Promise<void>

Stop the server and all plugins. Ensures graceful shutdown.

Properties

  • server: Server - Access the Fastify server instance wrapper
  • config: Config - Access the configuration manager
  • logger: Logger - Access the logger instance
  • alerts: Alerts - Access the alerts system
  • mocksManager: MocksManager - Access the mocks manager
  • pluginManager: PluginManager - Access the plugin manager
  • version: string - Current version of the core package

Plugin System

Create custom plugins to extend functionality:

interface Plugin {
  register?(coreApi: CoreApi): void;
  init?(): Promise<void>;
  start?(): Promise<void>;
  stop?(): Promise<void>;
}

interface PluginConstructor {
  id: string; // Unique plugin identifier
  new (coreApi: CoreApi, core: Core): Plugin;
}

interface CoreApi {
  config: Config;
  logger: Logger;
  alerts: Alerts;
  mocksManager: MocksManager;
  server: Server;
  version: string;
}

Architecture

Component Flow

Core (Orchestrator)
  ├── Config (Configuration Management)
  ├── Logger (Logging System)
  ├── Alerts (Alert Management)
  ├── MocksManager (Routes & Suites)
  ├── Server (Fastify HTTP Server)
  └── PluginManager (Plugin Lifecycle)

Lifecycle Sequence

  1. Construction: Core instantiates all components
  2. Registration: Plugins are registered with PluginManager
  3. Initialization (init()):
    • Config loads configuration files
    • MocksManager initializes and loads files
    • Plugins are registered and initialized
  4. Start (start()):
    • Server starts listening
    • MocksManager starts file watching
    • Plugins are started
  5. Stop (stop()):
    • Plugins are stopped
    • MocksManager stops file watching
    • Server closes gracefully

Dependencies

  • @dynamic-mock-server/config - Configuration management
  • @dynamic-mock-server/logger - Logging utilities
  • @dynamic-mock-server/alerts - Alert system
  • @dynamic-mock-server/mocks-manager - Mock management
  • fastify - HTTP server framework

Related Packages

License

Apache-2.0 © Miguel Martínez