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

hook-app

v1.0.0

Published

A dynamic framework to supercharge your Node.js applications with hooks.

Downloads

4

Readme

hook-app

npm version License: ISC

A WordPress-style hooks system for Node.js applications. Build modular, traceable, and extensible apps with lifecycle hooks, services, and features.

Installation

npm install hook-app
import hookApp from 'hook-app';

Quick Start

Create a simple app with a feature that runs during initialization:

import hookApp, { type RegisterContext } from 'hook-app';

const myFeature = ({ registerAction }: RegisterContext) => {
  registerAction({
    hook: '$INIT_FEATURE',
    handler: () => {
      console.log('Hello, Hook App!');
    },
  });
};

await hookApp({ features: [myFeature] });

Core Concepts

Hooks

Named extension points where actions can attach. Reference built-in hooks with $HOOK_NAME syntax:

registerAction({
  hook: '$INIT_FEATURE',  // Built-in lifecycle hook
  handler: () => { /* ... */ },
});

Actions

Functions that execute when a hook is triggered. Actions have a name, priority, and handler:

registerAction({
  hook: '$START',
  name: 'my-action',
  priority: 10,  // Higher = runs first
  handler: (args, ctx) => {
    // Your logic here
  },
});

Services & Features

  • Services - Core integrations that set up shared functionality (databases, logging, etc.)
  • Features - Application-specific logic built on top of services

Both use the same RegisterContext interface:

const myService = ({ registerAction, registerHook, createHook }: RegisterContext) => {
  // Register custom hooks, actions, etc.
};

await hookApp({
  services: [myService],
  features: [myFeature],
});

Lifecycle

Boot phases execute in this order:

START → SETTINGS → INIT_SERVICES → INIT_SERVICE → INIT_FEATURES → INIT_FEATURE
      → START_SERVICES → START_SERVICE → START_FEATURES → START_FEATURE → FINISH

Key Patterns

Custom Hook Communication

Features communicate through custom hooks:

import hookApp, { type RegisterContext } from 'hook-app';

// Feature 1: Registers and triggers a custom hook
const notifier = ({ registerHook, registerAction, createHook }: RegisterContext) => {
  registerHook({ NOTIFY: 'notify' });

  registerAction({
    hook: '$INIT_FEATURE',
    handler: () => {
      createHook.sync('notify', { message: 'Hello from notifier!' });
    },
  });
};

// Feature 2: Listens to the custom hook
const listener = ({ registerAction }: RegisterContext) => {
  registerAction({
    hook: '$NOTIFY',
    handler: (args) => {
      console.log('Received:', (args as { message: string }).message);
    },
  });
};

await hookApp({ features: [notifier, listener] });

Settings & Configuration

Access and modify settings using dot-notation paths:

import hookApp, { type RegisterContext } from 'hook-app';

const app = await hookApp({
  settings: {
    api: {
      baseUrl: 'https://api.example.com',
      timeout: 5000,
    },
  },
  features: [
    ({ registerAction }: RegisterContext) => {
      registerAction({
        hook: '$INIT_FEATURE',
        handler: ({ getConfig, setConfig }: RegisterContext) => {
          const url = getConfig<string>('api.baseUrl');
          console.log('API URL:', url);

          // Modify settings
          setConfig('api.timeout', 10000);
        },
      });
    },
  ],
});

// Access final settings
console.log(app.settings);

Hook Execution Modes

Choose how actions execute when a hook is triggered:

| Mode | Method | Description | |------|--------|-------------| | sync | createHook.sync(name, args?) | Synchronous execution | | serie | createHook.serie(name, args?) | Async, one at a time | | parallel | createHook.parallel(name, args?) | Async, all at once | | waterfall | createHook.waterfall(name, initial) | Pass result to next handler |

Waterfall example:

registerAction('transform', (value: number) => value + 1);
registerAction('transform', (value: number) => value * 2);

const result = createHook.waterfall('transform', 5);
// result.value === 12  (5 + 1 = 6, then 6 * 2 = 12)

Lifecycle Hooks Reference

| Hook | Execution | Description | |------|-----------|-------------| | $START | serie | App starting | | $SETTINGS | serie | Configure settings | | $INIT_SERVICES | parallel | Initialize all services | | $INIT_SERVICE | serie | Initialize each service | | $INIT_FEATURES | parallel | Initialize all features | | $INIT_FEATURE | serie | Initialize each feature | | $START_SERVICES | parallel | Start all services | | $START_SERVICE | serie | Start each service | | $START_FEATURES | parallel | Start all features | | $START_FEATURE | serie | Start each feature | | $FINISH | serie | App ready |

API Quick Reference

Main Entry

import hookApp from 'hook-app';

const app = await hookApp({
  services?: ServiceDef[],
  features?: FeatureDef[],
  settings?: Record<string, unknown> | ((ctx: RegisterContext) => Record<string, unknown>),
  context?: Record<string, unknown>,
  trace?: string | null,
});

// Returns: { settings, context }

Registration (inside services/features)

// Register an action on a hook
registerAction({
  hook: '$INIT_FEATURE',
  handler: (args, ctx) => { /* ... */ },
  name?: string,
  priority?: number,
});

// Shorthand forms
registerAction('hook-name', handler);
registerAction('hook-name', handler, { priority: 10 });

// Register a custom hook
registerHook({ MY_HOOK: 'my-hook' });

Hook Execution

// Synchronous
const results = createHook.sync('hook-name', args?);

// Async sequential
const results = await createHook.serie('hook-name', args?);

// Async parallel
const results = await createHook.parallel('hook-name', args?);

// Waterfall (pass value through handlers)
const { value, results } = createHook.waterfall('hook-name', initialValue);

Config & Context Access

// Get/set configuration
const value = getConfig<T>('path.to.value', defaultValue?);
setConfig('path.to.value', newValue);

// Get/set custom context
const value = getContext<T>('path.to.value', defaultValue?);
setContext('path.to.value', newValue);

Tracing

Enable boot tracing to debug your app's lifecycle:

await hookApp({
  trace: 'compact',  // 'full' | 'normal' | 'compact' | null
  features: [/* ... */],
});

License

ISC

Links