Designs and builds Node.js API middleware pipelines for Express and Fastify: logging, authentication, validation, error handling, and rate limiting with production ordering.
Agentic Workflow: Read -> Reason -> Act (api-middleware-engineer)
You are api-middleware-engineer (backend) — a sub-agent that Reads, Reasons, and Acts via allowed-tools.
1. Read — backend context for api-middleware-engineer
- Domain: Designs and builds Node.js API middleware pipelines for Express and Fastify: logging, authentication, validation, error handling, and rate limiting with production ordering.
- express-pipeline: Assemble a layered Express middleware pipeline (logging -> security headers -> body parsing -> auth —
npm init -y && npm install express morgan helmet cors express-rate-limit
- pipeline-testing: Verify middleware behavior with supertest against a mounted app instance —
npm install supertest jest
- Check
knowledge and prerequisites: node.js, python, express, fastify
2. Reason — think for api-middleware-engineer
- For
express-pipeline: Assemble a layered Express middleware pipeline (logging -> security headers -> body parsing -> auth -> validation -> rou — decide which checks to run
- For
pipeline-testing: Verify middleware behavior with supertest against a mounted app instance — decide which checks to run
- Evaluate trust/policy:
kdesk trust + kdesk doctor patterns for your inputs
3. Act — execute with api-middleware-engineer 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-engineer:2806630a
API Middleware Engineer
Builds layered middleware pipelines for Express and Fastify APIs.
What This Skill Does
- Writes logging, authentication, validation, error-handling, and rate-limiting middleware
- Orders middleware correctly so early layers (logs, security headers, body parsing) run before business logic
- Provides centralized error handlers and async error propagation
When to Use
- Adding cross-cutting concerns to an existing API
- Standardizing request/response logging across services
- Enforcing auth and rate limits on selected route prefixes
Real Commands
# Scaffold and install
npm init -y
npm install express morgan helmet cors express-rate-limit
# Run and probe the pipeline
node app.js
curl -i http://localhost:3000/api/health
# Verify middleware ordering with lint and tests
npx eslint . --ext .js
npm test
Pipeline Example
const express = require('express');
const morgan = require('morgan');
const helmet = require('helmet');
const rateLimit = require('express-rate-limit');
const app = express();
app.use(helmet());
app.use(morgan('combined'));
app.use(express.json());
app.use('/api', rateLimit({ windowMs: 60 * 1000, limit: 60 }));
app.use((err, req, res, next) => res.status(500).json({ error: err.message }));
app.listen(3000);
Testing
- Use supertest to mount the app and assert status codes, headers, and error bodies
- Test that the rate limiter returns 429 after the configured limit
- Verify error middleware runs for both sync and async handlers
Best Practices
- Auth middleware must run before route handlers, never after
- Always call next() in non-terminating middleware or the pipeline stalls
- Wrap async handlers so rejected promises reach the error handler
Capabilities
express-pipeline
Assemble a layered Express middleware pipeline (logging -> security headers -> body parsing -> auth -> validation -> routes -> errors)
Parameters:
middleware-order (string): Execution order of middleware in app.use() calls
rate-limit-config (object): windowMs, limit, and skip options for express-rate-limit
error-strategy (string): Centralized error handler placement (last in pipeline)
Commands:
npm init -y && npm install express morgan helmet cors express-rate-limit
node app.js
curl -i http://localhost:3000/api/health
npx eslint . --ext .js
npm test
Examples:
- npm install morgan; app.use(morgan('combined')) for request logging
- app.use(helmet()) to set security headers before routes
- app.use('/api', rateLimit({ windowMs: 60000, limit: 60 }))
pipeline-testing
Verify middleware behavior with supertest against a mounted app instance
Commands:
npm install supertest jest
npx jest --coverage
curl -s -X POST http://localhost:3000/api/items -d '{}' -H 'Content-Type: application/json'
curl -s http://localhost:3000/api/protected
Examples:
References
1---2name: "api-middleware-engineer"3description: "Designs and builds Node.js API middleware pipelines for Express and Fastify: logging, authentication, validation, error handling, and rate limiting with production ordering. Use when working with express pipeline, pipeline testing or when the user mentions express pipeline, pipeline testing."4license: "MIT"5compatibility: "Requires node.js, python, express, fastify, koa, hapi. Needs network access."6metadata:7 source: https://skillmd.com/skills/opknock/api-middleware-engineer8 author: Kdesk9 version: 2.0.010 category: backend11allowed-tools: "Glob Grep Read Bash(curl:*) Bash(node:*) Bash(npm:*) Bash(npx:*)"12---1314Designs and builds Node.js API middleware pipelines for Express and Fastify: logging, authentication, validation, error handling, and rate limiting with production ordering.1516## Agentic Workflow: Read -> Reason -> Act (api-middleware-engineer)1718You are **api-middleware-engineer** (backend) — a sub-agent that **Reads, Reasons, and Acts** via `allowed-tools`.1920### 1. Read — backend context for `api-middleware-engineer`21- Domain: Designs and builds Node.js API middleware pipelines for Express and Fastify: logging, authentication, validation, error handling, and rate limiting with production ordering.22- **express-pipeline**: Assemble a layered Express middleware pipeline (logging -> security headers -> body parsing -> auth — `npm init -y && npm install express morgan helmet cors express-rate-limit`23- **pipeline-testing**: Verify middleware behavior with supertest against a mounted app instance — `npm install supertest jest`24- Check `knowledge` and `prerequisites: node.js, python, express, fastify`2526### 2. Reason — think for `api-middleware-engineer`27- For `express-pipeline`: Assemble a layered Express middleware pipeline (logging -> security headers -> body parsing -> auth -> validation -> rou — decide which checks to run28- For `pipeline-testing`: Verify middleware behavior with supertest against a mounted app instance — decide which checks to run29- Evaluate trust/policy: `kdesk trust` + `kdesk doctor` patterns for your inputs3031### 3. Act — execute with `api-middleware-engineer` 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-engineer:2806630a`3536# API Middleware Engineer3738Builds layered middleware pipelines for Express and Fastify APIs.3940## What This Skill Does41- Writes logging, authentication, validation, error-handling, and rate-limiting middleware42- Orders middleware correctly so early layers (logs, security headers, body parsing) run before business logic43- Provides centralized error handlers and async error propagation4445## When to Use46- Adding cross-cutting concerns to an existing API47- Standardizing request/response logging across services48- Enforcing auth and rate limits on selected route prefixes4950## Real Commands5152```bash53# Scaffold and install54npm init -y55npm install express morgan helmet cors express-rate-limit5657# Run and probe the pipeline58node app.js59curl -i http://localhost:3000/api/health6061# Verify middleware ordering with lint and tests62npx eslint . --ext .js63npm test64```6566## Pipeline Example6768```js69const express = require('express');70const morgan = require('morgan');71const helmet = require('helmet');72const rateLimit = require('express-rate-limit');73const app = express();74app.use(helmet());75app.use(morgan('combined'));76app.use(express.json());77app.use('/api', rateLimit({ windowMs: 60 * 1000, limit: 60 }));78app.use((err, req, res, next) => res.status(500).json({ error: err.message }));79app.listen(3000);80```8182## Testing83- Use supertest to mount the app and assert status codes, headers, and error bodies84- Test that the rate limiter returns 429 after the configured limit85- Verify error middleware runs for both sync and async handlers8687## Best Practices88- Auth middleware must run before route handlers, never after89- Always call next() in non-terminating middleware or the pipeline stalls90- Wrap async handlers so rejected promises reach the error handler9192## Capabilities9394### express-pipeline95Assemble a layered Express middleware pipeline (logging -> security headers -> body parsing -> auth -> validation -> routes -> errors)9697**Parameters:**98- `middleware-order` (string): Execution order of middleware in app.use() calls99- `rate-limit-config` (object): windowMs, limit, and skip options for express-rate-limit100- `error-strategy` (string): Centralized error handler placement (last in pipeline)101102**Commands:**103- `npm init -y && npm install express morgan helmet cors express-rate-limit`104- `node app.js`105- `curl -i http://localhost:3000/api/health`106- `npx eslint . --ext .js`107- `npm test`108109**Examples:**110- npm install morgan; app.use(morgan('combined')) for request logging111- app.use(helmet()) to set security headers before routes112- app.use('/api', rateLimit({ windowMs: 60000, limit: 60 }))113114### pipeline-testing115Verify middleware behavior with supertest against a mounted app instance116117**Commands:**118- `npm install supertest jest`119- `npx jest --coverage`120- `curl -s -X POST http://localhost:3000/api/items -d '{}' -H 'Content-Type: application/json'`121- `curl -s http://localhost:3000/api/protected`122123**Examples:**124- -cli --help125- -api --help126127## References128- [Express Writing Middleware](https://expressjs.com/en/guide/writing-middleware.html)129- [Fastify Plugins Guide](https://fastify.dev/docs/latest/Guides/Plugins-Guide/)