nodejs-backend-patterns

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

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

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 access, and getting these wrong leads to fragile, hard-to-maintain services. ## Core Features & Use Cases - Framework Setup: Ready-to-use Express and Fastify configurations with security middleware (helmet, cors, compression) and schema-validated routes. - Layered Architecture: Complete controller, service, and repository layer implementations with dependency injection container wiring. - Middleware & Error Handling: JWT authentication, Zod validation, Redis-backed rate limiting, structured Pino logging, and a global error handler with custom error classes. - Use Case: When scaffolding a new REST API with user registration and login, apply the layered architecture, JWT auth service with refresh tokens, PostgreSQL repository with connection pooling, and Zod validation middleware to get a consistent, testable codebase. ## Quick Start Use the nodejs-backend-patterns skill to scaffold an Express REST API with JWT authentication, Zod validation, and a PostgreSQL-backed user service.

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?▼

Use a layered architecture with controllers handling HTTP requests, services containing business logic, and repositories managing data access. Wire them together with a dependency injection container that registers singletons for the database pool, repositories, and services.

Express vs Fastify for Node.js APIs?▼

Express offers a minimalist, middleware-centric ecosystem suited for general APIs, while Fastify provides higher performance with built-in schema validation and a plugin system. Both setups here include helmet, cors, and compression for security and response handling.

How to implement JWT authentication in Express?▼

Create an AuthService that verifies passwords with bcrypt and signs short-lived access tokens (15 minutes) plus refresh tokens (7 days) using jsonwebtoken. Protect routes with an authenticate middleware that verifies the Bearer token and attaches the payload to the request.

Does Express error handling work with async route handlers?▼

Express does not catch rejected promises from async handlers automatically, so wrap them in an asyncHandler that forwards errors to next(). A global error-handling middleware then maps custom AppError subclasses to proper status codes and hides details in production.

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

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

How to add rate limiting to a Node.js API with Redis?▼

Use express-rate-limit with a rate-limit-redis store backed by an ioredis client so limits are shared across instances. Apply a general limiter such as 100 requests per 15 minutes and a stricter limiter for authentication endpoints.