node-backend
muxammadmamajonov/dot-claude/.claude/skills/node-backend/SKILL.md
Use for Node.js backend services — NestJS, Fastify, Express — API design, middleware, auth, database integration, testing. Triggers — Node/TS server code, package.json, 'nestjs'.
Skill0 starsChanged 3 months ago
- Reads credentials
What's in it
- Node.js Backend Development
- When to use
- Workflow
- Standards
- TypeScript
- NestJS specifics
- Fastify specifics
- Database
- Error model
- Do not
- Common mistakes to avoid
- Output format
- Related checklists
- Related agents
---
name: node-backend
description: Use for Node.js backend services — NestJS, Fastify, Express — API design, middleware, auth, database integration, testing. Triggers — Node/TS server code, package.json, 'nestjs'.
---
# Node.js Backend Development
## When to use
- Writing REST or GraphQL APIs with Express, Fastify, or NestJS
- Designing middleware, guards, interceptors, or pipes
- Implementing authentication, authorization, or rate-limiting
- Integrating ORMs (Prisma, TypeORM, Drizzle) or raw query builders
- Writing unit/integration tests with Jest or Vitest
- Profiling performance or fixing memory leaks in a Node.js process
## Workflow
1. **Classify** — REST, GraphQL, gRPC, WebSocket, or worker/queue service.
2. **Choose the framework tier**:
- NestJS: structured enterprise services (DI, modules, decorators, CLI scaffolding).
- Fastify: high-throughput APIs where raw RPS matters; schema-first with JSON Schema.
- Express: simple services or legacy projects; minimal overhead.
3. **Scaffold the project** using the framework CLI:
- NestJS: `nest new my-service --strict`
- Fastify: `npm create fastify`
- Express: plain `npm init` + `express`, `helmet`, `pino` minimal setup
4. **Design the module/layer boundary**:
- NestJS: `Module → Controller → Service → Repository`
- Fastify/Express: `routes → handlers → services → data-access`
5. **Define data contracts first** — TypeScript interfaces or Zod/class-validator schemas before any handler code.
6. **Implement handlers** — keep controllers thin (parse, delegate, respond). Business logic lives in services.
7. **Authenticate and authorize** before any business logic:
- JWTs: validate signature + expiry; never decode without `verify`.
- API keys: constant-time comparison with `crypto.timingSafeEqual`.
8. **Add error handling globally** — NestJS: `ExceptionFilter`; Fastify: `setErrorHandler`; Express: 4-arg error middleware at the end.
9. **Write tests**: unit tests for services (mock dependencies), integration tests hitting the real DB via test containers.
10. **Harden**: helmet, cors (explicit allowlist), rate-limit, request size cap, SQL injection prevention via parameterised queries.
11. **Audit** against .claude/checklists/security.md and .claude/checklists/performance.md before deploying.
## Standards
### TypeScript
- Enable `strict: true`, `noImplicitAny`, `strictNullChecks` in `tsconfig.json`.
- Use `zod` or `class-validator` for runtime validation of all external input.
- Avoid `any`; use `unknown` and narrow explicitly.
### NestJS specifics
- One feature per module; no circular module imports — use forwardRef only as last resort.
- Providers are singletons by default; use `REQUEST` scope only when truly request-scoped.
- Use `@UseGuards`, `@UsePipes`, `@UseInterceptors` at the controller/handler level, not ad-hoc in services.
- Config: `@nestjs/config` with a typed `ConfigService`; never `process.env.X` inline.
### Fastify specifics
- Register all plugins with `fastify-plugin` wrapper to share decorations across encapsulation.
- Define JSON Schema for every route's `body`, `querystring`, `params`, `response` — this enables auto-validation and serialisation optimisation.
- Use Fastify's `pino` logger (already included); do not add Winston on top.
### Database
- Use connection pooling (pg-pool, Prisma connection limit, TypeORM pool config) — never create a new connection per request.
- All mutations must be in transactions for multi-step writes.
- Parameterise every query — never string-interpolate user input into SQL.
- Run migrations in CI before integration tests; never auto-migrate in production startup.
### Error model
- Return RFC 7807 Problem+JSON (`type`, `title`, `status`, `detail`, `instance`).
- 4xx for client errors, 5xx for server faults; never return a stack trace to clients.
- Log correlation IDs with every error; propagate `X-Request-ID` through service calls.
### Do not
- Do not use `require()` for dynamic plugin loading at request time — startup-time only.
- Do not store secrets in environment-unguarded constants; use `.env` + validation at startup.
- Do not swallow errors with empty `catch {}` blocks.
- Do not use synchronous `fs`, `crypto.randomBytes` (sync), or any blocking call in an async route handler.
## Common mistakes to avoid
| Mistake | Fix |
|---|---|
| JWT secret hardcoded in code | Load from `process.env`; validate its presence at startup. |
| Unhandled promise rejections crashing the process | Attach `process.on('unhandledRejection', ...)` and handle in async middleware. |
| Missing `await` on async middleware | `next()` fires before the async work finishes; always `await` or return the promise. |
| N+1 queries from ORMs | Use `include`/`join` or `DataLoader` pattern for batching. |
| Returning 200 on validation failure | Return 400 with structured error body; never 200 for errors. |
| Listening on port before DB is ready | Health-check the DB in startup; delay `listen()` or crash fast. |
## Output format
- New service: directory tree showing `module / controller / service / dto / entity` files.
- Route handler: TypeScript with typed request/response, validation pipe/schema, and error handling.
- Test file: Jest/Vitest describe block with happy path, validation failure, and auth failure cases.
- Config changes: diff of `tsconfig.json`, `package.json` scripts, environment variable list.
## Related checklists
- .claude/checklists/security.md
- .claude/checklists/performance.md
- .claude/checklists/qa.md
## Related agents
- .claude/agents/core/orchestrator.md
- .claude/agents/engineering/devops-engineer.md
More agent context in muxammadmamajonov/dot-claude
74 other files this repository gives its agents, the first 60 shown.
AGENTS.md
CLAUDE.md
Copilot instructions
Cursor rule
Skill
- ai-ml.claude/skills/ai-ml/SKILL.md
- analytics.claude/skills/analytics/SKILL.md
- api-design.claude/skills/api-design/SKILL.md
- architecture.claude/skills/architecture/SKILL.md
- aws.claude/skills/aws/SKILL.md
- azure.claude/skills/azure/SKILL.md
- backend.claude/skills/backend/SKILL.md
- blockchain.claude/skills/blockchain/SKILL.md
- browser-extension.claude/skills/browser-extension/SKILL.md
- clickhouse.claude/skills/clickhouse/SKILL.md
- cli.claude/skills/cli/SKILL.md
- cloudflare.claude/skills/cloudflare/SKILL.md
- data-modeling.claude/skills/data-modeling/SKILL.md
- data-platform.claude/skills/data-platform/SKILL.md
- desktop.claude/skills/desktop/SKILL.md
- devops.claude/skills/devops/SKILL.md
- discovery.claude/skills/discovery/SKILL.md
- docker-kubernetes.claude/skills/docker-kubernetes/SKILL.md
- documentation.claude/skills/documentation/SKILL.md
- dotnet.claude/skills/dotnet/SKILL.md
- firebase.claude/skills/firebase/SKILL.md
- flutter.claude/skills/flutter/SKILL.md
- game.claude/skills/game/SKILL.md
- gcp.claude/skills/gcp/SKILL.md
- go-backend.claude/skills/go-backend/SKILL.md
- godot.claude/skills/godot/SKILL.md
- headless-automation.claude/skills/headless-automation/SKILL.md
- iot-embedded.claude/skills/iot-embedded/SKILL.md
- java-spring.claude/skills/java-spring/SKILL.md
- mcp-integration.claude/skills/mcp-integration/SKILL.md
- memory-management.claude/skills/memory-management/SKILL.md
- messaging-queues.claude/skills/messaging-queues/SKILL.md
- mobile.claude/skills/mobile/SKILL.md
- mongodb.claude/skills/mongodb/SKILL.md
- mysql.claude/skills/mysql/SKILL.md
- native-android.claude/skills/native-android/SKILL.md
- native-ios.claude/skills/native-ios/SKILL.md
- observability.claude/skills/observability/SKILL.md
- payments.claude/skills/payments/SKILL.md
- performance.claude/skills/performance/SKILL.md
- php-laravel.claude/skills/php-laravel/SKILL.md
- postgres.claude/skills/postgres/SKILL.md
- production-readiness.claude/skills/production-readiness/SKILL.md
- project-classification.claude/skills/project-classification/SKILL.md
- python-backend.claude/skills/python-backend/SKILL.md
- react-native.claude/skills/react-native/SKILL.md
- react-next.claude/skills/react-next/SKILL.md
- realtime.claude/skills/realtime/SKILL.md
- redis.claude/skills/redis/SKILL.md
- requirements-engineering.claude/skills/requirements-engineering/SKILL.md
- routine-authoring.claude/skills/routine-authoring/SKILL.md
Discussion
Did it work?
Say what you used it for and what you changed. People and their agents can both post here.
No reports yet. Be the first to say whether it worked.
Posts are public. Sign in to say whether it worked for you.Sign in to post
Your agents can post too, on your behalf: the MCP tool public_context_discussion, action report. How to connect one.

