This skill teaches Node.js decision-making principles for 2025, not fixed code patterns to copy. Learn to THINK about architecture and choose frameworks based on context.
What This Skill Provides
The Node.js Best Practices skill provides comprehensive Node.js development principles covering framework selection, async patterns, architecture, error handling, validation, and security.Core Knowledge Areas
Framework Selection
Decision trees for Hono (edge), Fastify (performance), Express (stable), NestJS (enterprise)
Runtime Considerations
Node.js 22+ native TypeScript, ESM vs CommonJS, Bun vs Deno considerations
Async Patterns
Async/await, Promise.all, event loop awareness, I/O vs CPU-bound work
Architecture
Layered structure (Controller → Service → Repository), dependency injection
Error Handling
Centralized error handling, custom error classes, status code selection
Security
Input validation, parameterized queries, password hashing, JWT verification
When This Skill Is Loaded
Agents load this skill when:- Building Node.js applications or APIs
- Choosing frameworks for backend projects
- Implementing async patterns
- Designing backend architecture
- Handling errors and validation
- Securing Node.js applications
- Optimizing Node.js performance
- Writing tests for Node.js code
Use Cases
Framework Selection (2025)
Decision tree based on context:Framework Comparison
| Factor | Hono | Fastify | Express |
|---|---|---|---|
| Best for | Edge, serverless | Performance | Legacy, learning |
| Cold start | Fastest | Fast | Moderate |
| Ecosystem | Growing | Good | Largest |
| TypeScript | Native | Excellent | Good |
| Learning curve | Low | Medium | Low |
Runtime Considerations (2025)
Node.js
Use for:
- General purpose
- Largest ecosystem
- Native TS (22+)
- Production stability
Bun
Use for:
- Performance critical
- Built-in bundler
- Fast startup
- Modern tooling
Deno
Use for:
- Security-first
- Built-in TypeScript
- Web standards
- Fresh projects
Async Patterns Decision
When to Use Each Pattern
- async/await - Sequential async operations
- Promise.all - Parallel independent operations
- Promise.allSettled - Parallel where some can fail
- Promise.race - Timeout or first response wins
Event Loop Awareness
Key Principles
Layered Architecture
Request Flow:
- Controller/Route Layer - Handles HTTP specifics, input validation at boundary
- Service Layer - Business logic, framework-agnostic
- Repository Layer - Data access only, database queries
Error Handling Strategy
Client Gets
- Appropriate HTTP status
- Error code for handling
- User-friendly message
- NO internal details
Logs Get
- Full stack trace
- Request context
- User ID (if applicable)
- Timestamp
Status Code Selection
| Situation | Status | When |
|---|---|---|
| Bad input | 400 | Client sent invalid data |
| No auth | 401 | Missing/invalid credentials |
| No permission | 403 | Valid auth, not allowed |
| Not found | 404 | Resource doesn’t exist |
| Conflict | 409 | Duplicate or state conflict |
| Validation | 422 | Valid schema, business rules fail |
| Server error | 500 | Our fault, log everything |
Validation Strategy
Validate at boundaries:- API entry point (request body/params)
- Before database operations
- External data (API responses, file uploads)
- Environment variables (at startup)
| Library | Best For |
|---|---|
| Zod | TypeScript first, type inference |
| Valibot | Smaller bundle, tree-shakeable |
| ArkType | Performance critical |
| Yup | Existing React Form usage |
Related Skills
API Patterns
API design principles for REST, GraphQL, tRPC
Python Patterns
Alternative backend runtime patterns
Rust Pro
High-performance systems programming
Which Agents Use This Skill
Backend Specialist
The Backend Specialist loads this skill for all Node.js development work. It’s used alongside
api-patterns for API design and other runtime skills as needed.Security Checklist
Critical Security Measures:
- Input validation - All inputs validated
- Parameterized queries - No SQL string concatenation
- Password hashing - bcrypt or argon2
- JWT verification - Always verify signature and expiry
- Rate limiting - Protect from abuse
- Security headers - Helmet.js or equivalent
- HTTPS - Everywhere in production
- CORS - Properly configured
- Secrets - Environment variables only
- Dependencies - Regularly audited
Security Mindset
Testing Strategy
| Type | Purpose | Tools |
|---|---|---|
| Unit | Business logic | node:test, Vitest |
| Integration | API endpoints | Supertest |
| E2E | Full flows | Playwright |
Built-in Test Runner
Node.js 22+ includes native test runner:No external dependency needed, includes coverage reporting and watch mode.
Anti-Patterns to Avoid
Decision Checklist
Before implementing:
- Asked user about stack preference?
- Chosen framework for THIS context? (not just default)
- Considered deployment target? (edge/serverless/container)
- Planned error handling strategy?
- Identified validation points?
- Considered security requirements?
- Chosen testing approach?
Module System Decision
ESM (import/export)
Use for:
- Modern standard
- Better tree-shaking
- Async module loading
- New projects
CommonJS (require)
Use for:
- Legacy compatibility
- Existing codebases
- Some edge cases
