nodejs-backend-patterns

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

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

SYSTEM DOCUMENTATION & REQUIREMENTS

💡 This Skill includes references (resource) components.

What problem does it solve? Building production Node.js backends requires many decisions around framework choice, project structure, error handling, authentication, and database access. This Skill provides ready-to-apply TypeScript patterns so you avoid inconsistent architectures and common security mistakes. ## Core Features & Use Cases - Framework Setup: Express and Fastify server configuration with helmet, CORS, compression, and schema-validated routes. - Layered Architecture: Controller, service, and repository layers with dependency injection for testable, maintainable code. - Middleware & Error Handling: JWT authentication, Zod validation, Redis-backed rate limiting, structured logging, and a global error handler with custom error classes. - Data & Infrastructure Patterns: PostgreSQL connection pooling, MongoDB with Mongoose, transactions, JWT auth with refresh tokens, Redis caching, and standardized API responses. - Use Case: When scaffolding a new REST API, apply the layered architecture pattern with the auth middleware and global error handler to get a secure, consistent service skeleton in minutes. ## Quick Start Ask the AI to scaffold a Node.js Express API with layered architecture, JWT authentication, and centralized error handling using this skill.

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 Express backend project?

Use a layered architecture with controllers handling HTTP requests, services containing business logic, and repositories managing data access. Add separate directories for middleware, routes, config, and TypeScript types, then wire dependencies through a DI container.

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 size.

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.

Does this approach support both SQL and NoSQL databases?

Yes, it covers PostgreSQL using the pg Pool with connection limits and graceful shutdown, plus MongoDB through Mongoose with connection event handling and schema indexes. A transaction pattern with BEGIN, COMMIT, and ROLLBACK is included for multi-step writes.

How do I handle errors centrally in an Express application?

Define custom error classes extending a base AppError with status codes, then register a global error-handling middleware that maps known errors to responses and logs unexpected ones. Wrap async route handlers with an asyncHandler to forward rejections to the handler.

How do I add rate limiting to Node.js API endpoints?

Use express-rate-limit with a Redis store via rate-limit-redis so limits persist across instances. Apply a general limiter such as 100 requests per 15 minutes and a stricter limiter for authentication endpoints that skips successful requests.