node-best-practices

Provides Node.js and TypeScript best practices covering async patterns, error handling, streams, testing, and performance.

7|Updated May 13, 2026
One-click install
npx skills add https://github.com/DawnMoon1542/agents-skills --skill node-best-practices-dawnmoon1542
Or copy as Structured Prompt for Agent
Please help me install this Agent Skill.
Skill: node-best-practices
Source: https://github.com/DawnMoon1542/agents-skills/tree/main/node-best-practices
Command: npx skills add https://github.com/DawnMoon1542/agents-skills --skill node-best-practices-dawnmoon1542

SYSTEM DOCUMENTATION & REQUIREMENTS

What problem does it solve? Node.js developers often lack consistent, production-grade guidance on topics like native TypeScript type stripping, error handling, graceful shutdown, flaky test diagnosis, and performance profiling, leading to fragile applications and reinvented patterns. ## Core Features & Use Cases - Native TypeScript with Type Stripping: Configure Node.js 22+ to run .ts files directly without ts-node or build steps, including tsconfig.json and package.json setup. - Operational Patterns: Rule files covering error handling with typed error codes, graceful shutdown with close-with-grace, structured logging with pino, caching with async-cache-dedupe, and stream pipelines. - Testing & Performance: Diagnose flaky tests with node:test, profile CPU hotspots with @platformatic/flame, and benchmark HTTP servers with autocannon, wrk, or k6. - Use Case: When setting up a new Node.js 22+ TypeScript service, use this Skill to configure type stripping, add graceful shutdown handlers, validate environment variables with Zod, and write reliable tests with the built-in test runner. ## Quick Start Ask the assistant to set up a Node.js 22 TypeScript project with type stripping, graceful shutdown, and structured logging following best practices.

Frequently Asked Questions about node-best-practices

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

FAQPage Schema
How do I run TypeScript files directly in Node.js without ts-node?

Use Node.js type stripping: on Node 22.6+ run with --experimental-strip-types, and on Node 22.19+/23.6+/24+ run .ts files directly with no flags. Your code must use import type for type-only imports, avoid enums and namespaces, and use .ts extensions in imports.

How do I handle graceful shutdown in a Node.js server?

Use the close-with-grace package to register a shutdown handler that responds to SIGTERM and SIGINT. Inside the handler, stop accepting new requests, close the HTTP server, then close database and cache connections in reverse initialization order.

What is the best way to diagnose flaky tests in node:test?

Run tests with --test-reporter=spec and --test-timeout to identify hanging tests, then isolate files individually. Common causes include race conditions, hardcoded ports, shared module state, and unawaited promises; use dynamic port 0 and t.mock for determinism.

Does Node.js type stripping support enums and decorators?

No. Type stripping only removes type annotations without transforming code, so enums, namespaces, and constructor parameter properties are unsupported. Replace enums with const objects using as const and declare class properties explicitly.

Which caching library should I use for async operations in Node.js?

Use async-cache-dedupe for async caching with TTL, stale-while-revalidate, and automatic request deduplication, with optional Redis storage. For simple bounded in-memory caching, use lru-cache with max size and TTL options.

Why should I avoid using NODE_ENV for configuration?

NODE_ENV conflates environment detection, logging behavior, security settings, and optimization flags into one variable, causing hidden behavior changes. Use explicit environment variables per concern, validated with Zod or env-schema, for clearer and more testable configuration.