{"id":27885,"library":"jubi-middleware","title":"Jubi Middleware","description":"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.","status":"active","version":"1.0.88","language":"javascript","source_language":"en","source_url":null,"tags":["javascript"],"install":[{"cmd":"npm install jubi-middleware","lang":"bash","label":"npm"},{"cmd":"yarn add jubi-middleware","lang":"bash","label":"yarn"},{"cmd":"pnpm add jubi-middleware","lang":"bash","label":"pnpm"}],"dependencies":[],"imports":[{"note":"Named export; ESM-only since v1.0.0. CommonJS require works but destructure is required.","wrong":"const Middleware = require('jubi-middleware').Middleware","symbol":"Middleware","correct":"import { Middleware } from 'jubi-middleware'"},{"note":"Default export is not available. Use named import.","wrong":"import compose from 'jubi-middleware'","symbol":"compose","correct":"import { compose } from 'jubi-middleware'"},{"note":"Context is a type, only available as type import in TypeScript.","wrong":"import { Context } from 'jubi-middleware'","symbol":"Context","correct":"import type { Context } from 'jubi-middleware'"}],"quickstart":{"code":"import { compose, Middleware } from 'jubi-middleware';\n\n// Define middleware functions\nconst logger: Middleware = async (ctx, next) => {\n  console.log('Request:', ctx.req.method, ctx.req.url);\n  await next();\n  console.log('Response status:', ctx.res.statusCode);\n};\n\nconst auth: Middleware = async (ctx, next) => {\n  const token = ctx.req.headers['authorization'];\n  if (!token) {\n    ctx.res.statusCode = 401;\n    ctx.res.end('Unauthorized');\n    return;\n  }\n  ctx.user = { id: '123' };\n  await next();\n};\n\nconst handler: Middleware = async (ctx) => {\n  ctx.res.end('Hello, ' + (ctx.user?.id ?? 'World'));\n};\n\n// Compose and execute\nconst app = compose([logger, auth, handler]);\nconst ctx = {\n  req: { method: 'GET', url: '/', headers: { authorization: 'Bearer secret' } } as any,\n  res: new (require('stream').Writable)({\n    write(chunk: any) { console.log('Write:', chunk.toString()); },\n    end(chunk: any) { console.log('End:', chunk?.toString()); }\n  }) as any,\n};\napp(ctx).then(() => console.log('Done')).catch(console.error);","lang":"typescript","description":"Demonstrates composing and running a middleware chain with logger, auth, and handler."},"warnings":[{"fix":"Always await next() in middleware unless you intend to terminate the chain.","message":"Middleware functions must call `await next()` to pass control to the next middleware; otherwise the chain stops.","severity":"gotcha","affected_versions":">=1.0.0"},{"fix":"Be careful about modifying ctx; use it to pass data (e.g., ctx.user) but avoid unintended side effects.","message":"The context object (ctx) is mutable and shared across middleware. Mutations persist.","severity":"gotcha","affected_versions":">=1.0.0"},{"fix":"Update to v1.0.0+ and await the result of compose() if you relied on synchronous behavior.","message":"In 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.","severity":"breaking","affected_versions":"<1.0.0"}],"env_vars":null,"last_verified":"2026-05-09T00:00:00.000Z","next_check":"2026-08-07T00:00:00.000Z","problems":[{"fix":"Ensure each middleware has (ctx, next) => ... and calls await next() if needed.","cause":"Middleware function signature missing 'next' parameter or not calling next correctly.","error":"Error: next is not a function"},{"fix":"Provide a context with 'req' and 'res' properties as expected by the middleware.","cause":"Context object does not have 'req' property; you may be using the wrong context shape.","error":"TypeError: ctx.req is undefined"},{"fix":"Run 'npm install jubi-middleware' and use correct import: import { compose } from 'jubi-middleware'.","cause":"Package not installed or incorrect import path.","error":"Cannot find module 'jubi-middleware'"},{"fix":"Ensure next() is called exactly once (or not at all if terminating the chain).","cause":"Calling next() more than once in a single middleware execution.","error":"UnhandledPromiseRejectionWarning: Error: next() called multiple times"}],"ecosystem":"npm","meta_description":null,"install_score":null,"install_tag":null,"quickstart_score":null,"quickstart_tag":null}