Installs into .claude/skills of the current project.
Sponsors
SSkills DirectorySkills Directory
Know which skills are safe — weekly.
SSkills DirectorySkills Directory
Is that skill safe to install?
Are you the author of Node Api Services?
Add the live security badge to your README. It updates with every re-scan.
[](https://www.skillsdirectory.com/skills/ansh44233-node-api-services)
---
description: Build Node.js HTTP APIs (Express, Fastify, Hono, NestJS) with validation, errors, logging and graceful shutdown
profile: standard
languages: typescript
tags: node, api, backend
---
# Node.js API services
Use when adding or changing endpoints in a Node.js service.
## Request path
1. **Validate** params, query and body with a schema at the edge; return 400 with field-level messages. Never trust `req.body` types.
2. **Authorize** after authenticating: check the caller may act on *this* resource (object-level checks), not just that they are logged in.
3. **Do the work** in a service function that does not know about HTTP, so it can be tested directly.
4. **Respond** with a consistent shape and status code; never leak stack traces or SQL errors to clients.
## Errors
- Use one error-handling middleware (Express needs the 4-argument signature; Fastify uses `setErrorHandler`). Map known domain errors to 4xx, everything else to 500 with a request id.
- In Express 4, errors thrown inside `async` handlers are not caught automatically: wrap handlers or upgrade to Express 5.
- Handle `unhandledRejection` by logging and exiting; a process manager restarts it.
## Operations
- Structured JSON logs (pino) with a request id propagated to downstream calls. Do not log tokens, passwords or full bodies with personal data.
- Timeouts on every outbound call (`AbortSignal.timeout(ms)` with `fetch`). Retries only for idempotent requests, with backoff.
- Graceful shutdown on `SIGTERM`: stop accepting connections, finish in-flight requests, close the database pool, then exit.
- Configuration from environment variables parsed and validated once at startup; fail fast on missing values.
## Security checklist
Rate limits on auth and expensive routes · `helmet` (or equivalent) headers · CORS limited to known origins · body size limits · parameterized queries only · dependency audit in CI.
## Verify
Unit tests for the service function, an HTTP-level test (supertest or `app.inject`) for status codes and validation errors, then the full test suite and typecheck.