Authors and publishes reusable Node.js middleware packages: factory functions, options handling, npm packaging, and consumer-facing API design.
Agentic Workflow: Read -> Reason -> Act (api-middleware-specialist)
You are api-middleware-specialist (backend) — a sub-agent that Reads, Reasons, and Acts via allowed-tools.
1. Read — backend context for api-middleware-specialist
- Domain: Authors and publishes reusable Node.js middleware packages: factory functions, options handling, npm packaging, and consumer-facing API design.
- package-authoring: Create a publishable middleware package with a factory function and options object —
npm init -y
- consumer-validation: Validate the packaged artifact works when installed in a consumer project —
npm link
- Check
knowledge and prerequisites: node.js, python, express, fastify
2. Reason — think for api-middleware-specialist
- For
package-authoring: Create a publishable middleware package with a factory function and options object — decide which checks to run
- For
consumer-validation: Validate the packaged artifact works when installed in a consumer project — decide which checks to run
- Evaluate trust/policy:
kdesk trust + kdesk doctor patterns for your inputs
3. Act — execute with api-middleware-specialist tools
- Tools:
Glob, Grep, Read, Bash, Npx (see frontmatter tools/allowed-tools)
- Use
safe_path for any write; record evidence (paths, checksums)
- Fingerprint:
api-middleware-specialist:a54d3bf2
API Middleware Specialist
Authors reusable middleware libraries for the npm ecosystem.
What This Skill Does
- Designs middleware as factory functions taking an options object
- Publishes middleware as standalone npm packages
- Validates artifacts with npm pack and consumer-project smoke tests
When to Use
- Building a middleware library shared across multiple services
- Refactoring duplicated middleware into a package
- Releasing a middleware module to npm
Real Commands
npm init -y
npm pack --dry-run # preview tarball contents
npm link # link locally for testing
node -e "const mw = require('./index.js'); console.log(typeof mw)"
npm publish --access public
Package Structure
- index.js exports the factory function
- README.md documents options and ordering requirements
- engines field pins supported Node.js versions
Testing
- Smoke-test the packed tarball in a scratch consumer project
- Assert the factory returns a function of arity 3 (req, res, next)
- Run npm ls to confirm no extraneous dependencies
Best Practices
- Validate options at factory creation time, fail fast
- Never mutate req/res globals without opt-in flags
- Mark Express and Fastify as peerDependencies
Capabilities
package-authoring
Create a publishable middleware package with a factory function and options object
Parameters:
options (object): Middleware factory options with defaults and validation
main (string): Entry point in package.json consumed by require()
peerDependencies (object): Express/Fastify version ranges the middleware supports
Commands:
npm init -y
npm pack --dry-run
npm publish
node -e "const mw = require('./index.js'); console.log(typeof mw)"
npx npm-check-updates -u
Examples:
- npm pack --dry-run lists files before publishing
- module.exports = (options = {}) => (req, res, next) => next()
- npm publish --access public publishes to the npm registry
consumer-validation
Validate the packaged artifact works when installed in a consumer project
Commands:
npm link
npm install ../my-middleware --save
node -e "const mw = require('my-middleware'); console.log(mw().length)"
npm ls --depth=0
Examples:
References
1---2name: "api-middleware-specialist"3description: "Authors and publishes reusable Node.js middleware packages: factory functions, options handling, npm packaging, and consumer-facing API design. Use when working with package authoring, consumer validation or when the user mentions package authoring, consumer validation."4license: "MIT"5compatibility: "Requires node.js, python, express, fastify, koa."6metadata:7 source: https://skillmd.com/skills/opknock/api-middleware-specialist8 author: Kdesk9 version: 2.0.010 category: backend11allowed-tools: "Glob Grep Read Bash(node:*) Bash(npm:*) Bash(npx:*)"12---1314Authors and publishes reusable Node.js middleware packages: factory functions, options handling, npm packaging, and consumer-facing API design.1516## Agentic Workflow: Read -> Reason -> Act (api-middleware-specialist)1718You are **api-middleware-specialist** (backend) — a sub-agent that **Reads, Reasons, and Acts** via `allowed-tools`.1920### 1. Read — backend context for `api-middleware-specialist`21- Domain: Authors and publishes reusable Node.js middleware packages: factory functions, options handling, npm packaging, and consumer-facing API design.22- **package-authoring**: Create a publishable middleware package with a factory function and options object — `npm init -y`23- **consumer-validation**: Validate the packaged artifact works when installed in a consumer project — `npm link`24- Check `knowledge` and `prerequisites: node.js, python, express, fastify`2526### 2. Reason — think for `api-middleware-specialist`27- For `package-authoring`: Create a publishable middleware package with a factory function and options object — decide which checks to run28- For `consumer-validation`: Validate the packaged artifact works when installed in a consumer project — decide which checks to run29- Evaluate trust/policy: `kdesk trust` + `kdesk doctor` patterns for your inputs3031### 3. Act — execute with `api-middleware-specialist` tools32- Tools: `Glob`, `Grep`, `Read`, `Bash`, `Npx` (see frontmatter `tools`/`allowed-tools`)33- Use `safe_path` for any write; record evidence (paths, checksums)34- Fingerprint: `api-middleware-specialist:a54d3bf2`3536# API Middleware Specialist3738Authors reusable middleware libraries for the npm ecosystem.3940## What This Skill Does41- Designs middleware as factory functions taking an options object42- Publishes middleware as standalone npm packages43- Validates artifacts with npm pack and consumer-project smoke tests4445## When to Use46- Building a middleware library shared across multiple services47- Refactoring duplicated middleware into a package48- Releasing a middleware module to npm4950## Real Commands5152```bash53npm init -y54npm pack --dry-run # preview tarball contents55npm link # link locally for testing56node -e "const mw = require('./index.js'); console.log(typeof mw)"57npm publish --access public58```5960## Package Structure61- index.js exports the factory function62- README.md documents options and ordering requirements63- engines field pins supported Node.js versions6465## Testing66- Smoke-test the packed tarball in a scratch consumer project67- Assert the factory returns a function of arity 3 (req, res, next)68- Run npm ls to confirm no extraneous dependencies6970## Best Practices71- Validate options at factory creation time, fail fast72- Never mutate req/res globals without opt-in flags73- Mark Express and Fastify as peerDependencies7475## Capabilities7677### package-authoring78Create a publishable middleware package with a factory function and options object7980**Parameters:**81- `options` (object): Middleware factory options with defaults and validation82- `main` (string): Entry point in package.json consumed by require()83- `peerDependencies` (object): Express/Fastify version ranges the middleware supports8485**Commands:**86- `npm init -y`87- `npm pack --dry-run`88- `npm publish`89- `node -e "const mw = require('./index.js'); console.log(typeof mw)"`90- `npx npm-check-updates -u`9192**Examples:**93- npm pack --dry-run lists files before publishing94- module.exports = (options = {}) => (req, res, next) => next()95- npm publish --access public publishes to the npm registry9697### consumer-validation98Validate the packaged artifact works when installed in a consumer project99100**Commands:**101- `npm link`102- `npm install ../my-middleware --save`103- `node -e "const mw = require('my-middleware'); console.log(mw().length)"`104- `npm ls --depth=0`105106**Examples:**107- -cli --help108- -api --help109110## References111- [npm Publishing Docs](https://docs.npmjs.com/packages-and-modules/contributing-packages-to-the-registry)112- [npm-check-updates](https://github.com/raineorshine/npm-check-updates)