{"id":24949,"library":"azure-middleware","title":"Azure Middleware Engine","description":"Azure Middleware Engine is a Node.js middleware engine for Azure Functions, inspired by Express, Fastify, and Hapi. Version 1.0.1 (stable) provides an intuitive API to apply middleware patterns in Azure Functions. It supports sequential middleware execution, conditional middleware via useIf, and validation. Alternatives like Azure Functions middleware libraries often lack chainable API or conditional execution. The package is lightweight with no external runtime dependencies, requiring Node >=8.9.4. It helps separate concerns like input parsing, validation, and error handling from business logic.","status":"active","version":"1.0.1","language":"javascript","source_language":"en","source_url":"https://github.com/emanuelcasco/azure-middleware","tags":["javascript","azure","middlewares","middleware handler","middleware engine","azure functions"],"install":[{"cmd":"npm install azure-middleware","lang":"bash","label":"npm"},{"cmd":"yarn add azure-middleware","lang":"bash","label":"yarn"},{"cmd":"pnpm add azure-middleware","lang":"bash","label":"pnpm"}],"dependencies":[],"imports":[{"note":"Named export; common mistake to use default import.","wrong":"const MiddlewareHandler = require('azure-middleware');","symbol":"MiddlewareHandler","correct":"const { MiddlewareHandler } = require('azure-middleware');"},{"note":"ESM import available in Node versions supporting it.","wrong":"import MiddlewareHandler from 'azure-middleware';","symbol":"MiddlewareHandler (ESM)","correct":"import { MiddlewareHandler } from 'azure-middleware';"},{"note":"Default export is an object with MiddlewareHandler property.","wrong":null,"symbol":"azure-middleware (CommonJS entire module)","correct":"const azureMiddleware = require('azure-middleware');"}],"quickstart":{"code":"const { MiddlewareHandler } = require('azure-middleware');\n\nconst myFunction = new MiddlewareHandler()\n  .use((context, next) => {\n    context.log.info('First middleware');\n    next();\n  })\n  .use((context, next) => {\n    context.log.info('Second middleware');\n    context.done(null, { body: 'Hello from Azure Function', status: 200 });\n  })\n  .listen();\n\nmodule.exports = myFunction;","lang":"javascript","description":"Shows basic middleware chain with context logging and response via context.done."},"warnings":[{"fix":"Always call context.next() in async or callback-style middlewares.","message":"Missing next() call causes pipeline to hang.","severity":"gotcha","affected_versions":"*"},{"fix":"Ensure only one middleware calls context.done() and that it's called after all next() calls.","message":"context.done() must be called exactly once; multiple calls may lead to race conditions.","severity":"gotcha","affected_versions":"*"},{"fix":"Ensure predicate function returns a boolean or a promise resolving to boolean.","message":"useIf predicate must return a boolean synchronously or via promise.","severity":"gotcha","affected_versions":"*"}],"env_vars":null,"last_verified":"2026-05-01T00:00:00.000Z","next_check":"2026-07-30T00:00:00.000Z","problems":[{"fix":"Use const { MiddlewareHandler } = require('azure-middleware');","cause":"Importing the module incorrectly as default instead of named export.","error":"TypeError: MiddlewareHandler is not a constructor"},{"fix":"Ensure next() is called only once per middleware and not after context.done().","cause":"Calling next() more than once in a single middleware or after done().","error":"Error: next() called multiple times"},{"fix":"Design pipeline so that only one middleware calls done() (typically the last).","cause":"Calling context.done() multiple times in the pipeline.","error":"Error: done already called"}],"ecosystem":"npm","meta_description":null,"install_score":null,"install_tag":null,"quickstart_score":null,"quickstart_tag":null}