Registry / web-framework / azure-middleware

azure-middleware

JSON →
library1.0.1jsnpmunverified

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.

npm install azure-middleware
INSTALL
IMPORT
SIG · AZURE-MIDDLEWARE
A
azure-middleware
web-frameworkjavascriptv1.0.1
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.

MiddlewareHandler
const { MiddlewareHandler } = require('azure-middleware');
const MiddlewareHandler = require('azure-middleware');
Named export; common mistake to use default import.
MiddlewareHandler (ESM)
import { MiddlewareHandler } from 'azure-middleware';
import MiddlewareHandler from 'azure-middleware';
ESM import available in Node versions supporting it.
azure-middleware (CommonJS entire module)
const azureMiddleware = require('azure-middleware');
Default export is an object with MiddlewareHandler property.

Shows basic middleware chain with context logging and response via context.done.

const { MiddlewareHandler } = require('azure-middleware'); const myFunction = new MiddlewareHandler() .use((context, next) => { context.log.info('First middleware'); next(); }) .use((context, next) => { context.log.info('Second middleware'); context.done(null, { body: 'Hello from Azure Function', status: 200 }); }) .listen(); module.exports = myFunction;
Debug
Known issues
gotchaMissing next() call causes pipeline to hang.
fix
Always call context.next() in async or callback-style middlewares.
affects: *
gotchacontext.done() must be called exactly once; multiple calls may lead to race conditions.
fix
Ensure only one middleware calls context.done() and that it's called after all next() calls.
affects: *
gotchauseIf predicate must return a boolean synchronously or via promise.
fix
Ensure predicate function returns a boolean or a promise resolving to boolean.
affects: *
Errors
Common errors & fixes
TypeError: MiddlewareHandler is not a constructor
Importing the module incorrectly as default instead of named export.
fix
Use const { MiddlewareHandler } = require('azure-middleware');
Error: next() called multiple times
Calling next() more than once in a single middleware or after done().
fix
Ensure next() is called only once per middleware and not after context.done().
Error: done already called
Calling context.done() multiple times in the pipeline.
fix
Design pipeline so that only one middleware calls done() (typically the last).
Upgrade
Version history
1.0.1latest on npm
Audit
Dependencies

No dependency data recorded yet.

Agent activity
21 hits · last 30 days
node
16
OpenAI (training)
1
Resources
azure-middleware — npm install azure-middleware · libregistry