Loading...
Loading...
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.
npx skill4agent add iliaal/ai-skills nodejs-backend| 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 |
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 interfacesimport type { }interfaceunknownanyz.infer<typeof Schema>asdeclare module 'pkg' { const v: unknown; export default v; }types/ambient.d.ts.extend().pick().omit().partial().merge()AppError(message, statusCode, isOperational)ValidationError(400)NotFoundError(404)UnauthorizedError(401)ForbiddenError(403)ConflictError(409)AppError{ error: message }const asyncHandler = (fn) => (req, res, next) => Promise.resolve(fn(req, res, next)).catch(next);/users/users/:id/orders/api/v1/{ data, pagination?: { page, limit, total, totalPages } }{ error: { code, message, details? } }?page=1&limit=20&status=active&sort=createdAt,descLocation| Pattern | Use When |
|---|---|
| Sequential operations |
| Parallel independent ops |
| Parallel, some may fail |
| Timeout or first-wins |
readFileSync