Nodejs backend

From iliaal/whetstone · View interactive version

Nodejs backend is an AI agent skill from the GitHub repository iliaal/whetstone. Node.js backend patterns: framework selection, layered architecture, TypeScript, validation, error handling, security, production deployment. Use when building REST APIs, Express/Fastify servers, microservices, or server-side TypeScript.

How to use this skill

Skill file

Node.js Backend

Framework Selection

| Context | Choose | Why |

|---------|--------|-----|

| Edge/Serverless | Hono | Zero-dep, fastest cold starts |

| Performance API | Fastify | 2-3x faster than Express, built-in schema validation |

| Enterprise/team | NestJS | DI, decorators, structured conventions |

| Legacy/ecosystem | Express | Most middleware, widest adoption |

Ask user: deployment target, cold start needs, team experience, existing codebase.

Architecture

src/
├── routes/          # HTTP: parse request, call service, format response
├── middleware/       # Auth, validation, rate limiting, logging
├── services/        # Business logic (no HTTP types)
├── repositories/    # Data access only (queries, ORM)
├── config/          # Env, DB pool, constants
└── types/           # Shared TypeScript interfaces

TypeScript Rules

Validation

Zod (TypeScript inference) or TypeBox (Fastify native). Validate at boundaries only: request entry, before DB ops, env vars at startup. Use .extend(), .pick(), .omit(), .partial(), .merge() for DRY schemas.

Error Handling

Custom error hierarchy: AppError(message, statusCode, isOperational) → ValidationError(400), NotFoundError(404), UnauthorizedError(401), ForbiddenError(403), ConflictError(409)

Centralized handler middleware:

Codes: 400 bad input | 401 no auth | 403 no permission | 404 missing | 409 conflict | 422 business rule | 429 rate limited | 500 server fault

API Design

Async Patterns

| Pattern | Use When |

|---------|----------|

| async/await | Sequential operations |

| Promise.all | Parallel independent ops |

| Promise.allSettled | Parallel, some may fail |

| Promise.race | Timeout or first-wins |

Never readFileSync / sync methods in production. Offload CPU work to worker threads. Stream large payloads.

Discipline

References

Use this skill with your AI agent: Open on Skill Issue to copy, download, or add to your library. Works with Claude, ChatGPT, Gemini, Cursor, Windsurf and more.