{"success":true,"name":"send-exactly-one-response-per-request-in-node-js-handlers","description":"Node.js handler errors like 'headers already sent' or hanging requests.","category":"ai-brimind","path":"ai-brimind/send-exactly-one-response-per-request-in-node-js-handlers/SKILL.md","file":"SKILL.md","content":"---\nname: send-exactly-one-response-per-request-in-node-js-handlers\ndescription: \"Node.js handler errors like 'headers already sent' or hanging requests.\"\n---\n\n# Send Exactly One Response Per Request in Node.js Handlers\n\n## When to use\nProject is a Node.js API, and a handler has multiple res.send/res.json branches, or you see ERR_HTTP_HEADERS_SENT or requests that never finish.\n\n## Example request\nres.json inside an if, code continues, second res.json fires → 'headers already sent' — every response needs a return in front of it. Validation fails, error sent, but the DB call still runs after → the response ended but the handler didn't — return early. A branch where no res.* is ever called → the client waits until timeout — every path must end in exactly one response or next(err). res.send inside a callback AND after it → async branches double-respond — one exit per path.\n\n## Instructions\nAct as a Node.js developer who audits every handler for the invariant: each request path ends in EXACTLY one response (or one next(err)) — no more, no fewer. Walk every branch of the handler including early validations, catch blocks, and async callbacks, and check two failure modes: (1) double response — a res.send/res.json not followed by return, letting execution continue into another response; the fix is 'return res.status(...).json(...)' as a reflex on every early exit; (2) missing response — a branch (often an else, or an empty catch) where no res.* and no next(err) is ever reached, which hangs the client until timeout. When ERR_HTTP_HEADERS_SENT appears, do not patch it with res.headersSent checks — that masks the symptom; find the path that responds twice, that's the root cause. Async code deserves extra suspicion: a response inside a callback plus code after the callback is the classic double-fire. Only sign off once you have traced every branch to exactly one terminal (response or next(err)), and name which branch previously violated it.\n\n## Metadata\n- role: developer\n- level: tactical\n- places: vibeCoding\n- origin: ai.brimind.pro skill #999\n","linked_files":[],"origin":"ai.brimind.pro","owner_id":null,"source":"router"}