Node.js
Who this is for
Section titled “Who this is for”Engineers on a Node.js project.
When to use it
Section titled “When to use it”When you write or review backend Node.js code.
- Must: Follow Engineering for Git, review, tests-in-general, and Delivery. This page adds only Node.js API rules.
- Must: HTTP APIs have a consistent error shape (status code + machine-readable code or message). Do not leak stack traces to clients.
- Must: Validate input at the boundary (params, query, body) before business logic. Reject bad input with 4xx, not a crash.
- Must: Authn/authz checks live in one obvious place per route (middleware or equivalent). Do not trust a client-supplied “user id” without verifying the session or token.
- Should: Structure the app so transport (HTTP) is separate from domain logic. New endpoints follow the folders the repo already uses.
- Should: Log request id, route, and outcome. Do not log secrets, tokens, or full payloads that contain client data.
- Should: Integration-test the API contract for the change (status + body shape), not only unit-test internals. See Automated tests.
- Team decides: Framework (Express, Fastify, Nest, Next route handlers) and ORM. Record them in the README.
What good looks like
Section titled “What good looks like”A reviewer can find validation, auth, and error handling without hunting. Failed requests are safe to show a client.
What to do
Section titled “What to do”- Check Git and review on the shared pages first.
- Add or change the route in the existing layout.
- Validate input, then authorize, then run the use case.
- Map failures to the standard error shape.
- Add an API test for the new or changed contract.