Registry / web-framework / jubi-middleware

jubi-middleware

JSON →
library1.0.88jsnpmunverified

A lightweight middleware library for Node.js (v1.0.88, actively maintained). It provides a simple and flexible way to compose asynchronous middleware chains, similar to Koa or Express but with a minimal API surface. Key differentiators: zero dependencies, TypeScript-first design with built-in types, and a focus on performance. It is intended for use in HTTP server frameworks or custom middleware pipelines. Current version 1.0.88 is stable; new releases appear monthly.

npm install jubi-middleware
INSTALL
IMPORT
SIG · JUBI-MIDDLEWARE
J
jubi-middleware
web-frameworkjavascriptv1.0.88
harness data pending
Install & Compatibility
Where this runs

No compatibility data collected yet for this library.

Code
Verified usage

Verified import paths — ran on the pinned version, not inferred.

Middleware
import { Middleware } from 'jubi-middleware'
const Middleware = require('jubi-middleware').Middleware
Named export; ESM-only since v1.0.0. CommonJS require works but destructure is required.
compose
import { compose } from 'jubi-middleware'
import compose from 'jubi-middleware'
Default export is not available. Use named import.
Context
import type { Context } from 'jubi-middleware'
import { Context } from 'jubi-middleware'
Context is a type, only available as type import in TypeScript.

Demonstrates composing and running a middleware chain with logger, auth, and handler.

import { compose, Middleware } from 'jubi-middleware'; // Define middleware functions const logger: Middleware = async (ctx, next) => { console.log('Request:', ctx.req.method, ctx.req.url); await next(); console.log('Response status:', ctx.res.statusCode); }; const auth: Middleware = async (ctx, next) => { const token = ctx.req.headers['authorization']; if (!token) { ctx.res.statusCode = 401; ctx.res.end('Unauthorized'); return; } ctx.user = { id: '123' }; await next(); }; const handler: Middleware = async (ctx) => { ctx.res.end('Hello, ' + (ctx.user?.id ?? 'World')); }; // Compose and execute const app = compose([logger, auth, handler]); const ctx = { req: { method: 'GET', url: '/', headers: { authorization: 'Bearer secret' } } as any, res: new (require('stream').Writable)({ write(chunk: any) { console.log('Write:', chunk.toString()); }, end(chunk: any) { console.log('End:', chunk?.toString()); } }) as any, }; app(ctx).then(() => console.log('Done')).catch(console.error);
Debug
Known issues
gotchaMiddleware functions must call `await next()` to pass control to the next middleware; otherwise the chain stops.
fix
Always await next() in middleware unless you intend to terminate the chain.
affects: >=1.0.0
gotchaThe context object (ctx) is mutable and shared across middleware. Mutations persist.
fix
Be careful about modifying ctx; use it to pass data (e.g., ctx.user) but avoid unintended side effects.
affects: >=1.0.0
breakingIn v1.0.0, the compose function returned a promise that resolves when the chain completes. In earlier alpha versions, it did not return a promise.
fix
Update to v1.0.0+ and await the result of compose() if you relied on synchronous behavior.
affects: <1.0.0
Errors
Common errors & fixes
Error: next is not a function
Middleware function signature missing 'next' parameter or not calling next correctly.
fix
Ensure each middleware has (ctx, next) => ... and calls await next() if needed.
TypeError: ctx.req is undefined
Context object does not have 'req' property; you may be using the wrong context shape.
fix
Provide a context with 'req' and 'res' properties as expected by the middleware.
Cannot find module 'jubi-middleware'
Package not installed or incorrect import path.
fix
Run 'npm install jubi-middleware' and use correct import: import { compose } from 'jubi-middleware'.
UnhandledPromiseRejectionWarning: Error: next() called multiple times
Calling next() more than once in a single middleware execution.
fix
Ensure next() is called exactly once (or not at all if terminating the chain).
Upgrade
Version history
1.0.88latest on npm
Audit
Dependencies

No dependency data recorded yet.

Agent activity
35 hits · last 30 days
node
32
OpenAI (training)
1
Resources
jubi-middleware — npm install jubi-middleware · libregistry