nodejs-backend-patterns

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

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

SYSTEM DOCUMENTATION & REQUIREMENTS

💡 This Skill includes references (resource) components.

What problem does it solve? Building production Node.js backends requires many decisions around architecture, middleware, error handling, authentication, and database integration, and inconsistent implementations lead to fragile APIs that are hard to maintain and scale. ## Core Features & Use Cases - Framework Setup: Provides Express and Fastify server configurations with security middleware (helmet, cors, compression) and structured logging via Pino. - Layered Architecture: Implements controller, service, and repository layers with dependency injection for testable, maintainable codebases. - Security & Reliability: Covers JWT authentication with refresh tokens, Zod-based validation middleware, Redis-backed rate limiting, custom error classes, and a global error handler. - Use Case: When building a REST API for user management, apply the layered pattern with a UserController, UserService, and UserRepository backed by a PostgreSQL connection pool, protected by JWT auth and rate limiting. ## Quick Start Ask the AI to scaffold a Node.js Express REST API with layered architecture, JWT authentication, Zod validation, and PostgreSQL integration following 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 Express backend project?

Use a layered architecture with controllers handling HTTP requests, services containing business logic, and repositories managing data access. Wire dependencies through a DI container so each layer can be tested and replaced independently.

How to implement JWT authentication in Express middleware?

Create an authenticate middleware that extracts the Bearer token from the Authorization header and verifies it with jsonwebtoken. Attach the decoded payload to the request object, and issue short-lived access tokens (15m) alongside 7-day refresh tokens.

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

Express offers a minimalist, widely adopted ecosystem, while Fastify provides higher throughput with built-in schema validation and Pino logging. Choose Fastify for performance-sensitive services and Express for maximum middleware compatibility.

How do I handle database transactions in Node.js with PostgreSQL?

Acquire a client from the pg Pool, run BEGIN, execute your queries, then COMMIT on success or ROLLBACK on error, always releasing the client in a finally block. This keeps multi-step writes like order creation atomic.

Why use Redis for rate limiting instead of in-memory limits?

Redis-backed rate limiting via rate-limit-redis shares counters across multiple server instances, so limits hold under horizontal scaling. In-memory stores reset per process and per instance, allowing clients to exceed intended quotas.

What are the limitations of class-based layered architecture in Node.js?

Layered class architecture adds boilerplate and indirection that may be excessive for small services or prototypes. For simple CRUD APIs, a flat route-handler structure with direct database calls can be faster to ship and easier to read.