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

@epiijs/server

v4.0.0

Published

A simple server framework.

Readme

@epiijs/server

A simple server framework.

  • Koa-like pipeline
  • file-system based routing
  • handler chain with stacks
  • service dependency injection
  • pluggable logging

v4.x is only for ES module.

Install

npm i @epiijs/server --save

Usage

project like this

(root)
├─ src
│  ├─ handlers
│  │  ├─ users
│  │  │  └─ index.ts
│  │  └─ index.ts
│  └─ services
│     └─ userService.ts
└─ start.ts

will route requests like this

=> /users    (declare routes)
=> /         (filesystem fallback)

start server

import { startServer } from '@epiijs/server';

startServer({
  root: __dirname // or getDirNameByImportMeta(import.meta)
});

handle request by handler

Provide request handlers in /handlers. Recommend using declare to explicitly register routes:

import {
  HandlerDeclareResult,
  HandlerResult,
  IncomingMessageWithParams,
  ServiceLocator
} from '@epiijs/server';

export function declare(): HandlerDeclareResult {
  return {
    routes: [
      { method: 'GET', path: '/users' },
      { method: 'GET', path: '/users/:id' }
    ]
  };
}

export default async function (
  this: ServiceLocator,
  message: IncomingMessageWithParams
): Promise<HandlerResult> {
  const { method, params } = message;

  // simple response
  return 'hello world';

  // custom response
  return {
    status: 400,
    headers: { 'content-type': 'application/json' },
    content: JSON.stringify({})
  };
}

filter pipeline by handler chain

Use stacks in declare() to compose handler chain (Koa-like onion model):

import {
  HandlerDeclareResult,
  HandlerFn,
  HandlerResult,
  IncomingMessageWithParams,
  ServiceLocator
} from '@epiijs/server';

async function withMethodCheck(
  this: ServiceLocator,
  message: IncomingMessageWithParams,
  next: () => Promise<HandlerResult>
): Promise<HandlerResult> {
  if (message.method !== 'GET') {
    return { status: 405, content: 'method not allowed' };
  }
  return next();
}

async function withTiming(
  this: ServiceLocator,
  message: IncomingMessageWithParams,
  next: () => Promise<HandlerResult>
): Promise<HandlerResult> {
  const start = Date.now();
  const result = await next();
  console.log('elapsed', Date.now() - start);
  return result;
}

export function declare(): HandlerDeclareResult {
  return {
    routes: [{ method: 'GET', path: '/hello' }],
    stacks: [withTiming, withMethodCheck]
  };
}

export default async function (
  this: ServiceLocator,
  message: IncomingMessageWithParams
): Promise<HandlerResult> {
  return 'hello world';
}

inject service as dependency

Provide service factory in /services.

export interface IUserService {
  findUsers: () => Promise<IUser[]>;
}

export default function (services: ServiceLocator): IUserService {
  return {
    findUsers: async () => []
  };
}

Access service via this (bound as ServiceLocator) in handler:

import {
  HandlerResult,
  IncomingMessageWithParams,
  ServiceLocator
} from '@epiijs/server';

export default async function (
  this: ServiceLocator,
  message: IncomingMessageWithParams
): Promise<HandlerResult> {
  const userService = this.userService as IUserService;
  const users = await userService.findUsers();
  return users;
}

customize logging

import { setTransport } from '@epiijs/server';

setTransport((method, ...args) => {
  // method = 'info' | 'error' | 'warn' | 'debug' | 'log' | ...
  // route to your logger
});

Access logger via this.appLogger in handler:

export default async function (
  this: ServiceLocator,
  message: IncomingMessageWithParams
): Promise<HandlerResult> {
  this.appLogger.info('processing request', message.url);
  return 'ok';
}

Migration from V3

directory

actions/   →  handlers/

handler signature

// V3
export default async function (props: IncomingMessage, context: Context): Promise<ActionResult> {
  const userService = await context.useService('UserService');
  const config = context.getAppConfig();
  // ...
}

// V4
export default async function (
  this: ServiceLocator,
  message: IncomingMessageWithParams
): Promise<HandlerResult> {
  const userService = this.userService as IUserService;
  const config = this.appConfig as IAppConfig;
  // ...
}

pipeline (useHandler → stacks)

// V3
await context.useHandler(dispose => {
  const start = Date.now();
  if (message.method !== 'GET') {
    return { status: 405, content: 'method not allowed' };
  }
  dispose(() => console.log('elapsed', Date.now() - start));
});

// V4 — declare stacks
async function withMethodCheck(this: ServiceLocator, message: IncomingMessageWithParams, next: () => Promise<HandlerResult>) {
  if (message.method !== 'GET') {
    return { status: 405, content: 'method not allowed' };
  }
  return next();
}

async function withTiming(this: ServiceLocator, message: IncomingMessageWithParams, next: () => Promise<HandlerResult>) {
  const start = Date.now();
  const result = await next();
  console.log('elapsed', Date.now() - start);
  return result;
}

export function declare() {
  return {
    routes: [{ method: 'GET', path: '/hello' }],
    stacks: [withTiming, withMethodCheck]
  };
}

early return

// V3
throw new BreakActionError({ status: 403, content: 'forbidden' });

// V4 — return directly, do not call next()
return { status: 403, content: 'forbidden' };

type renames

| V3 | V4 | |----|----| | ActionResult | HandlerResult | | ActionFn | HandlerFn | | ActionDeclareResult | HandlerDeclareResult | | Context | removed |

Document