Master 1Password: vaults, Watchtower, passkeys, SSH agent, CLI, and family/team administration. Use when getting full value from 1Password personally or administering it for others.
中文简介正在准备中。当前显示原文说明。
Express.js API guidance — routing, middleware architecture, error handling, security hardening, and production setup.
中文简介正在准备中。当前显示原文说明。
查看安装方法安装前可以查看交给 AI 代理的指令内容。
Express is the minimal, unopinionated web framework for Node.js — routing plus middleware, and deliberately little else. Its power is the middleware pipeline: every request flows through a composable chain you fully control. The flip side is that Express makes no decisions for you — validation, auth, structure, and security are all yours. This skill covers building Express services that stay maintainable and safe, from middleware design to production hardening.
app.use(fn). Each middleware can end the response or call next(). Order is everything — auth before routes, body parsing before validation, error handler last.(err, req, res, next) catches errors. Async route errors must be forwarded — wrap handlers or use a helper, otherwise rejections escape Express entirely.express.Router() groups routes by domain (/users, /orders). Mount them on the app; keep route files thin and push logic into services.express-rate-limit) protects login/webhook endpoints; cors needs explicit origin configuration. Express ships none of this by default.res.locals passes data down the middleware chain (authenticated user, tenant); prefer it over mutating req with ad-hoc properties.next('route') and next('router'). Skip remaining handlers in the current route or router — useful for conditional middleware chains, but easy to misuse; prefer explicit branching.res.write() + res.end() for SSE and chunked responses; remember to handle client disconnects (req.on('close')) so you don't keep generating for nobody.src/
app.js # middleware wiring, mounts routers
routes/ # thin route definitions
services/ # business logic
middleware/ # auth, validation, errors
index.js # listen() only
app.use(helmet());
app.use(express.json({ limit: "100kb" }));
app.use("/api", routes);
app.use((req, res) => res.status(404).json({ error: "not_found" }));
app.use(errorHandler); // (err, req, res, next) — must be last
index.js (listen) separate from app.js (the configured app) so tests can import the app without binding a port.const validate = (schema) => (req, res, next) => {
const result = schema.safeParse({ body: req.body, query: req.query, params: req.params });
if (!result.success) return res.status(400).json({ error: "invalid_input", details: result.error.flatten() });
req.validated = result.data;
next();
};
asyncHandler wrapper so thrown errors reach your error middleware:
const asyncHandler = (fn) => (req, res, next) => Promise.resolve(fn(req, res, next)).catch(next);
app.set("trust proxy", 1)), set body limits, add rate limits on sensitive routes, disable x-powered-by (helmet does this), and enforce timeouts.
server.keepAliveTimeout and server.headersTimeout appropriately when behind a load balancer to avoid idle-connection drops./health, and track 5xx rate and p95 latency as your primary health metrics.req.body.req.body shape is the fastest path to injection bugs and 500s.trust proxy misconfigured — wrong and req.ip is the load balancer's; rate limiting and audit logs become useless.res.send() — "headers already sent" crashes; guard or return after sending.cors() with no origin config on an API with credentials; lock origins explicitly.还没有评价。欢迎分享你的使用感受。
无需登录即可发表。欢迎分享使用感受、提问,或说明在哪些环境下无法运行。
还没有评论。来写第一条吧。
Master 1Password: vaults, Watchtower, passkeys, SSH agent, CLI, and family/team administration. Use when getting full value from 1Password personally or administering it for others.
中文简介正在准备中。当前显示原文说明。
Create 3D visuals with modeling, texturing, lighting, rendering, and optimization for web and product.
中文简介正在准备中。当前显示原文说明。
Create 3D web experiences: scene setup, models, materials, lighting, animation, scroll-driven scenes, and performance budgets. Use when adding 3D to websites beyond basic demos.
中文简介正在准备中。当前显示原文说明。
Writing abstracts that get papers read — structured content, the 5-sentence core, and journal-specific constraints.
中文简介正在准备中。当前显示原文说明。
Learn effectively from courses and academies: choosing programs, studying actively, and converting courses into skills. Use when investing time/money in structured learning.
中文简介正在准备中。当前显示原文说明。
Audit designs for accessibility with WCAG checklists covering color, type, focus, motion, and content.
中文简介正在准备中。当前显示原文说明。