nodejs-backend-patterns

Implements Node.js backend services with Express, Fastify, middleware, authentication, and database patterns.

Updated Jun 8, 2026
One-click install
npx skills add https://github.com/raulisai/eva02 --skill nodejs-backend-patterns-raulisai
Or copy as Structured Prompt for Agent
Please help me install this Agent Skill.
Skill: nodejs-backend-patterns
Source: https://github.com/raulisai/eva02/tree/main/.agents/skills/nodejs-backend-patterns
Command: npx skills add https://github.com/raulisai/eva02 --skill nodejs-backend-patterns-raulisai

SYSTEM DOCUMENTATION & REQUIREMENTS

💡 This Skill includes references (resource) components.

What problem does it solve? Building production Node.js backends requires many architectural decisions—middleware ordering, error handling, authentication, database access, and caching—and getting them wrong leads to fragile, hard-to-maintain services. This Skill provides proven patterns and working TypeScript code for each layer of a backend application. ## Core Features & Use Cases - Framework Setup: Ready-to-use Express and Fastify server configurations with security middleware (helmet, CORS, compression) and structured logging via Pino. - Layered Architecture: Complete controller-service-repository implementation with dependency injection container, custom error classes, and a global error handler. - Auth, Validation & Infrastructure: JWT authentication with refresh tokens, Zod-based request validation, Redis-backed rate limiting and caching, PostgreSQL connection pooling, MongoDB/Mongoose integration, and transaction handling. - Use Case: When scaffolding a new REST API, apply the layered architecture pattern with the auth middleware, validation middleware, and repository layer to get a consistent, testable codebase without designing each piece from scratch. ## Quick Start Ask the AI to scaffold a Node.js REST API with Express, JWT authentication, Zod validation, and a PostgreSQL repository layer using these backend patterns.

Frequently Asked Questions about nodejs-backend-patterns

High-intent search queries and answers about installing and using this skill.

FAQPage Schema
How do I structure a Node.js backend with Express and TypeScript?

Use a layered architecture with controllers handling HTTP requests, services containing business logic, and repositories managing data access. Wire the layers together with a dependency injection container and add a global error handler middleware for consistent error responses.

Express vs Fastify for Node.js APIs, which should I use?

Express offers a minimalist, widely adopted middleware ecosystem, while Fastify provides higher performance with built-in schema validation and Pino logging. Both setups in this Skill include helmet, CORS, and compression for security and response optimization.

How do I implement JWT authentication in Express middleware?

Create an authenticate middleware that extracts the Bearer token from the Authorization header, verifies it with jsonwebtoken, and attaches the payload to the request object. Pair short-lived 15-minute access tokens with 7-day refresh tokens for session management.

How do I validate request bodies in Node.js APIs?

Use Zod schemas with a validation middleware that parses body, query, and params before the controller runs. Validation failures are converted into a ValidationError with field-level messages returned as a 400 response.

Does this approach support both PostgreSQL and MongoDB?

Yes. PostgreSQL uses the pg Pool with connection limits and graceful shutdown, while MongoDB uses Mongoose with connection pooling and schema definitions. A transaction pattern with BEGIN, COMMIT, and ROLLBACK is provided for multi-step PostgreSQL operations.

How do I add rate limiting to Express with Redis?

Use express-rate-limit with rate-limit-redis as the store, backed by an ioredis client. Configure a general API limiter such as 100 requests per 15 minutes and a stricter limiter for authentication endpoints that skips successful requests.