mcpField
N
nodejs-best-practices

nodejs-best-practices

github.com/nearformDevelopment79 installs
Repository

About nodejs-best-practices

nodejs-best-practices is a Nearform-maintained guide for developers building, reviewing, or refactoring Node.js and Fastify applications. Its 48 rules are organized into eight categories and prioritized by impact, covering topics such as performance, security, APIs, error handling, and monitoring.

Key features

  1. 0148 rules across eight categories
  2. 02Priorities based on impact
  3. 03Guidance for Node.js and Fastify
  4. 04Correct and incorrect code examples
  5. 05Individual rule files and a compiled guide

Use cases

  1. 01Design new Node.js APIs or Fastify routes
  2. 02Review database operations and API performance
  3. 03Address security, error handling, and logging concerns
  4. 04Refactor applications or optimize API response times

Install

Copy the command and run it in a terminal.

$npx skills add https://github.com/nearform/agent-skills --skill nodejs-best-practices

After installing, type/nodejs-best-practicesin Claude Code to confirm it loaded.

Bundled files

References and scripts installed along with SKILL.md.

AGENTS.md
metadata.json
README.md
rules/
_sections.md
_template.md
api-connection-pooling.md
api-n-plus-one.md
api-pagination.md
api-query-optimization.md
api-rest-design.md
api-transactions.md
async-backpressure.md
async-error-handling.md
async-parallel.md
async-queue-management.md
async-rate-limiting.md
async-timeout.md
cache-database.md
cache-http-headers.md
cache-invalidation.md
cache-lru.md
cache-redis.md
cache-stale-revalidate.md
code-config-management.md
code-dependency-injection.md
code-env-variables.md
code-module-structure.md
code-testing.md
code-typescript.md
error-async-errors.md

Details

From the project README

Node.js Best Practices

Comprehensive guide for Node.js and Fastify applications, maintained by Nearform. Contains 48 rules across 8 categories, prioritized by impact to guide automated refactoring and code generation.

When to Apply

Reference these guidelines when:

  • Writing new Node.js APIs or Fastify routes
  • Implementing database operations
  • Reviewing code for performance or security issues
  • Refactoring existing Node.js/Fastify code
  • Optimizing API response times
  • Handling errors and logging
  • Setting up monitoring and observability

Rule Categories by Priority

PriorityCategoryImpactPrefix
1Performance & SecurityCRITICALperf-
2API Design & DatabaseCRITICALapi-
3Error Handling & LoggingHIGHerror-
4Fastify OptimizationMEDIUM-HIGHfastify-
5Async PatternsMEDIUMasync-
6Caching & StateMEDIUMcache-
7Code OrganizationLOW-MEDIUMcode-
8Monitoring & DiagnosticsLOWmonitor-

Quick Reference

1. Performance & Security (CRITICAL)
  • perf-block-event-loop - Detect and prevent event loop blocking
  • perf-security-headers - Implement essential security headers
  • perf-input-validation - Validate and sanitize all inputs
  • perf-streaming - Use streams for large payloads
  • perf-memory-leaks - Prevent memory leaks
  • perf-compression - Implement compression strategies
2. API Design & Database (CRITICAL)
  • api-rest-design - Follow RESTful design principles
  • api-pagination - Implement efficient pagination
  • api-connection-pooling - Use connection pooling
  • api-query-optimization - Optimize database queries
  • api-n-plus-one - Prevent N+1 query problems
  • api-transactions - Handle transactions properly
3. Error Handling & Logging (HIGH)
  • error-middleware - Centralize error handling
  • error-structured-logging - Use structured logging (Pino)
  • error-async-errors - Handle async errors properly
  • error-sensitive-data - Don't leak sensitive data in errors
  • error-unhandled-rejection - Handle unhandled rejections
  • error-request-logging - Log requests efficiently
4. Fastify Optimization (MEDIUM-HIGH)
  • fastify-schema-validation - Use JSON schema validation
  • fastify-hooks - Optimize hook usage
  • fastify-plugins - Design reusable plugins
  • fastify-decorators - Use decorators effectively
  • fastify-serialization - Optimize JSON serialization
  • fastify-content-type - Handle content types properly
5. Async Patterns (MEDIUM)
  • async-parallel - Parallelize independent operations
  • async-error-handling - Handle async errors gracefully
  • async-backpressure - Handle backpressure in streams
  • async-rate-limiting - Implement rate limiting
  • async-queue-management - Use queues for background jobs
  • async-timeout - Set timeouts for operations
6. Caching & State (MEDIUM)
  • cache-lru - Use in-memory LRU caching
  • cache-redis - Implement Redis caching
  • cache-http-headers - Use HTTP caching headers
  • cache-invalidation - Implement cache invalidation
  • cache-stale-revalidate - Use stale-while-revalidate pattern
  • cache-database - Cache database queries
7. Code Organization (LOW-MEDIUM)
  • code-module-structure - Organize code by feature
  • code-dependency-injection - Use dependency injection
  • code-config-management - Manage configuration properly
  • code-env-variables - Handle environment variables
  • code-testing - Write testable code
  • code-typescript - Use TypeScript effectively
8. Monitoring & Diagnostics (LOW)
  • monitor-health-check - Implement health check endpoints
  • monitor-metrics - Collect application metrics
  • monitor-apm - Integrate APM tools
  • monitor-memory - Monitor memory usage
  • monitor-cpu - Profile CPU usage
  • monitor-distributed-tracing - Implement distributed tracing

How to Use

Read individual rule files for detailed explanations and code examples:

rules/perf-block-event-loop.md
rules/api-n-plus-one.md
rules/_sections.md

Each rule file contains:

  • Brief explanation of why it matters
  • Incorrect code example with explanation
  • Correct code example with explanation
  • Additional context and references

Full Compiled Document

For the complete guide with all rules expanded: AGENTS.md

Comments

Markdown supported