nodejs-best-practices

Structure Express routes, services, and database queries with error handling and tests.

3|Updated Dec 14, 2025
One-click install
npx skills add https://github.com/fil512/upship --skill nodejs-best-practices-fil512
Or copy as Structured Prompt for Agent
Please help me install this Agent Skill.
Skill: nodejs-best-practices
Source: https://github.com/fil512/upship/tree/main/.claude/skills/nodejs-best-practices
Command: npx skills add https://github.com/fil512/upship --skill nodejs-best-practices-fil512

SYSTEM DOCUMENTATION & REQUIREMENTS

What problem does it solve?

Coding Node.js projects often suffer from tangled routes, duplicated business logic, and unsafe database interactions. This Skill provides a structured approach to organize Express routes, services, and database access with consistent async/await usage, parameterized queries, error handling, and tested patterns.

Core Features & Use Cases

  • Separation of concerns: Routes delegate to services, keeping business logic out of HTTP handlers.
  • Database reliability: Use connection pooling, transactions with proper rollback, and safe query patterns.
  • Testing and security: Patterns for Jest tests, mock setups, and secure configuration practices.

Quick Start

Refactor an existing Express route to delegate to a service, ensure all database calls use parameterized queries, and wrap multi-step operations in a transaction when modifying multiple tables.

Frequently Asked Questions about nodejs-best-practices

High-intent search queries and answers about installing and using this skill.

FAQPage Schema
How do I structure Express routes to separate business logic from HTTP handlers?

Separate Express routes from business logic by delegating HTTP handler requests to dedicated service layers. This separation of concerns keeps routes clean and moves complex logic into maintainable, testable service modules.

What's the best way to handle database transactions and rollbacks in Node.js?

Handle database transactions in Node.js by using connection pooling and wrapping multi-step operations in a single transaction with proper rollback. This ensures data reliability when modifying multiple tables simultaneously.

How do I write Jest tests for Node.js services that use database queries?

Write Jest tests for Node.js services by setting up mock configurations for database query layers. Testing patterns focus on isolating service logic through mocks to ensure maintainable and comprehensive coverage.

Why should I use parameterized queries in Node.js database interactions?

Parameterized queries in Node.js prevent unsafe database interactions by separating SQL code from user input data. This secure configuration practice protects against injection attacks while maintaining reliable query execution.

Can I use this approach to refactor an existing Express application safely?

You can refactor existing Express applications by progressively moving business logic into services, converting database calls to parameterized queries, and wrapping multi-table modifications in transactions with rollback support.

What patterns help maintain clean async/await usage in Node.js backends?

Maintain clean async/await usage in Node.js backends by applying consistent error handling and proper separation of concerns across Express routes, service layers, and database access points to prevent tangled logic.