nodejs-backend-patterns

Implements production Node.js backend patterns for APIs, authentication, databases, and middleware.

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

SYSTEM DOCUMENTATION & REQUIREMENTS

💡 This Skill includes references (resource) components.

What problem does it solve? Building production Node.js backends requires many architectural decisions—layered structure, dependency injection, error handling, authentication, caching—and getting them wrong leads to fragile, hard-to-maintain services. This Skill provides proven TypeScript patterns and working code examples so you can implement these concerns correctly from the start. ## Core Features & Use Cases - Layered Architecture: Controller, service, and repository layers with TypeScript examples for Express and Fastify, including schema validation with Zod. - Security & Middleware: JWT authentication with refresh tokens, role-based authorization, rate limiting with Redis, and structured request logging with Pino. - Data & Infrastructure Patterns: PostgreSQL connection pooling, MongoDB/Mongoose setup, transaction handling, Redis caching with a @Cacheable decorator, and standardized API responses. - Use Case: When scaffolding a new REST API, use this Skill to generate the error-handling middleware, custom error classes, and a DI container wiring repositories to services to controllers. ## Quick Start Ask the agent to scaffold a Node.js user service with layered architecture, JWT authentication, and centralized error handling 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 layered architecture?

Separate code into controllers handling HTTP requests, services containing business logic, and repositories managing data access. Wire them together with a dependency injection container so each layer depends on abstractions, making the code testable and maintainable.

How to implement JWT authentication with refresh tokens in Express?

Issue a short-lived access token (15 minutes) and a longer-lived refresh token (7 days) signed with separate secrets. Verify the access token in authentication middleware, and expose a refresh endpoint that validates the refresh token and issues a new access token.

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 patterns are covered; choose Fastify for performance-critical services and Express for ecosystem maturity.

Does this approach support both SQL and NoSQL databases?

Yes, it covers PostgreSQL with the pg Pool for connection pooling and transactions, plus MongoDB with Mongoose for schema definition and connection management. Both include graceful shutdown handling for production deployments.

How do I handle errors centrally in an Express application?

Define custom error classes like ValidationError and NotFoundError extending a base AppError with status codes. Register a global error-handling middleware last that maps known errors to proper responses and logs unexpected errors without leaking details in production.

How to 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 to API routes and a stricter limiter to authentication endpoints, skipping successful requests for auth throttling.