/major-ai-skills:expressfrom major-ai-skills
Ship Express.js APIs with ordered middleware, Express 5 async errors, zod validation, safe trust proxy, and Prisma/Postgres workers agents routinely misconfigure.
Ships in major-ai-skills. Installing the plugin adds it to Claude Code.
What the skill costs in Claude's context, stage by stage
Name and description: Claude knows it exists.
SKILL.md joins the conversation and stays.
Read when SKILL.md points to them.
Express is a minimal Node HTTP framework of middleware chains and routers. Requests flow top-to-bottom; handlers must end the cycle or call next(). Express 5 forwards rejected promises from async handlers to error middleware automatically; Express 4 needs an async wrapper or explicit .catch(next). Agents validate input (zod/joi), mount 4-arg error middleware last, set trust proxy to hop count—not true, and keep persistence in @prisma / @postgresql with workers for slow jobs (@redis queues).
┌─────────────────────────────────────────────────────────────┐
│ Express middleware pipeline │
│ │
│ Client → reverse proxy / LB (@nginx) │
│ → Node process (PM2 / systemd / container) │
│ → helmet / cors / logger │
│ → express.json({ limit }) │
│ → auth / rate-limit (uses req.ip ← trust proxy) │
│ → Router("/api/…") → async handler │
│ ├── validate (zod) → service → @prisma │
│ └── next(err) → error middleware → JSON │
│ │
│ Side paths: BullMQ/worker processes → @redis │
└─────────────────────────────────────────────────────────────┘
Use when
req.ip.Do not use when
@graphql-apis (may still mount on Express).@nodejs.trust proxy to true without a stripping edge proxy → refuse; use hop count / subnet.catch(next) or requests hang/crash.(err, req, res, next) last. Missing 4th arg = not an error handler.express.json({ limit: "100kb" }) (tune per upload path); never unbounded JSON parse on public routes.req.body / params / query; return 400 with stable error shape.trust proxy: prefer app.set("trust proxy", 1) (or subnet list) behind one LB; never blind true unless the edge strips client-supplied X-Forwarded-*.app for tests (supertest); call listen only from server.js / bin entry.@redis; do not block the event loop on multi-second I/O.src/app.ts (Express 5-friendly; works on 4 with asyncHandler):
import express from "express";
import helmet from "helmet";
import { z } from "zod";
import { PrismaClient } from "@prisma/client";
const prisma = new PrismaClient();
export const app = express();
app.set("trust proxy", 1); // one reverse-proxy hop
app.use(helmet());
app.use(express.json({ limit: "100kb" }));
const createItem = z.object({
sku: z.string().min(1).max(64),
qty: z.number().int().min(0),
});
const items = express.Router();
items.get("/", async (_req, res) => {
const rows = await prisma.item.findMany({ take: 100 });
res.json(rows);
});
items.post("/", async (req, res) => {
const parsed = createItem.safeParse(req.body);
if (!parsed.success) {
res.status(400).json({ error: "validation_failed", details: parsed.error.flatten() });
return;
}
const row = await prisma.item.create({ data: parsed.data });
res.status(201).json(row);
});
app.get("/health", (_req, res) => res.json({ ok: true }));
app.use("/items", items);
app.use((err: any, _req, res, _next) => {
const status = typeof err.status === "number" ? err.status : 500;
if (status >= 500) console.error(err);
res.status(status).json({ error: status === 500 ? "internal_error" : err.message });
});
src/server.ts:
import { app } from "./app.js";
const port = Number(process.env.PORT ?? 3000);
app.listen(port, "0.0.0.0", () => {
console.log(`listening on ${port}`);
});
Commands:
npm ci
npx prisma migrate deploy # release step — pair @prisma @postgresql
NODE_ENV=production node dist/server.js
# tests: node --test / vitest + supertest(app)
Express 4 async helper (if not on Express 5):
const asyncHandler = (fn) => (req, res, next) => Promise.resolve(fn(req, res, next)).catch(next);
| Signature | Likely cause | Fix path |
|---|---|---|
| Request hangs after async throw | Express 4 unhandled rejection | Upgrade to 5 or wrap with catch(next) |
| Error middleware never runs | Mounted before routes or 3-arg signature | Move last; use (err, req, res, next) |
| Rate limit / audit IP always same or spoofable | trust proxy false or true | Set hop count / trusted subnets; harden proxy headers |
PayloadTooLargeError | Body over limit | Raise limit only on upload routes; reject elsewhere |
| CORS preflight fails | Missing options handler / wrong origin | Configure cors with explicit origins in prod |
| Prisma client errors on cold start | Migrate not deployed / wrong DATABASE_URL | prisma migrate deploy; verify env (@prisma) |
| Process dies on uncaughtException | Error escaped middleware | Fix handler; use process manager restart—do not “swallow” with uncaughtException listeners |
error, optional details); never leak stack traces to clients in prod.@types/express matching Express major (@typescript).prisma.$disconnect().routes/ + services/ + thin app.ts; keep secrets in env only.@github-actions and image builds with @docker.ws / Socket.IO alongside Express; not built-in.@prisma, @redis).@nodejs — runtime, ESM, process managers, signals@typescript — typing Express handlers and zod schemas@prisma — migrations and type-safe queries behind routes@postgresql — indexes and connection limits under Node pools@redis — queues/cache for background work@docker — containerize Node + healthchecksMANDATORY: Match Express 4 vs 5 error behavior. Mount 4-arg error middleware last. Validate all inputs. Set
trust proxyto real hop/subnet—not blindtrue. Never inventDATABASE_URLor API keys. Offload slow work to workers; exportappfor tests and bind0.0.0.0in containers.
What SKILL.md sets; muted values are Claude Code's defaults
npx claudepluginhub alivirgo/major-ai-skills --plugin major-ai-skills412 skills in this plugin
/3d-slicerAutomate 3D Slicer research workflows with MRML, VTK/ITK, DICOM data, and Segment Editor. Use for software workflows, not clinical interpretation./abbreviated-git-statusInspect Git branch, staging, and working-tree changes with short or porcelain status output when a compact repository check is needed./ableton-liveAutomate Ableton Live sessions with Python MIDI Remote Scripts, Max for Live, AbletonOSC, and Link synchronization./act-as-a-personal-tutorExplain a subject step by step, assess prior knowledge, and use short exercises to check understanding before advancing.Other plugins' skills for the same job