11ai Node.js API routes
Version baseline: Node.js 24.x Krypton LTS, using the latest security patch in that release line (24.18.0 at this review). Do not silently move an existing application between Node release lines; inspect engines, runtime files, CI, and deployment support first.
Treat a route as a public contract: method, path, parameters, authentication, validation, status codes, response shape, error behavior, and tests all matter. Inspect the project before editing and do not invent a framework, URL shape, identifier format, response envelope, or persistence layer when the repository already provides one.
Discover the route architecture
Identify:
- the server entrypoint and router composition;
- the framework and version;
- route modules, controllers, handlers, and middleware order;
- path prefixes and versioning such as
/apior/v1; - existing patterns for async errors, dependency injection, response serialization, and status codes;
- the nearest analogous route and its focused test.
Useful searches include:
rg -n "app\.(get|post|put|patch|delete|use)\(|router\.(get|post|put|patch|delete|use)\(|fastify\.(get|post|put|patch|delete)\(|@(?:Get|Post|Put|Patch|Delete)\(" src test tests
Add or change a route
- Translate the request into a small contract: method, path, inputs, auth, success status/body, and expected failures.
- Find the closest existing route and follow its file boundaries and naming.
- Register the route in the correct router and prefix; verify that the router is actually mounted.
- Keep the handler thin. Put business logic in the project's existing service/use-case layer when one exists.
- Reuse existing validation, authentication, error middleware, logging, and response helpers. Do not create a second pattern for the same concern.
- Preserve idempotency and status-code semantics. Do not turn a read into a write or broaden an existing route's authorization accidentally.
- Add focused tests for the happy path, malformed or missing input, unauthorized access when relevant, not-found/conflict behavior, and unexpected failures.
Verify routing
Run the narrowest route test first, then use a harmless request against a local server if appropriate:
curl -i http://localhost:PORT/EXACT/PATH
For a 404, distinguish an unregistered route from an application-level not-found response by checking router mounting, path prefixes, HTTP method, and the server instance under test. For a 405, inspect method registration and any method-not-allowed middleware.
Reporting
Report the final method/path contract, files changed, middleware and validation applied, tests run, and any assumptions. Call out breaking changes explicitly, especially renamed paths, changed status codes, response envelopes, or authorization requirements.