# Nodejs

> Node.js server development patterns including async patterns, error handling, and security best practices. Use when this capability is needed.

- Skill: `tomevault-io/nodejs` (Agent Skill, multi-file: 2 files)
- Install (CLI): `npx skillmds@latest add tomevault-io/nodejs`
- Raw SKILL.md: https://api.skillmd.com/api/skills/tomevault-io/nodejs/raw
- Safety review: pending (external: skill-scanner PASS, skillspector PASS)
- Works with: Claude Code, Claude.ai, OpenAI Codex
- Category: Security
- Author: tomevault-io (https://skillmd.com/u/tomevault-io)
- Updated: 2026-09-17
- Page: https://skillmd.com/skills/tomevault-io/nodejs

---


# Node.js Best Practices

## Project Structure
- src/ for source code
- src/lib/ for utilities
- src/types/ for TypeScript types
- tests/ for test files
- Keep entry point minimal

## Async Patterns
- Use async/await everywhere
- Handle all promise rejections
- Use Promise.all for parallel tasks
- Use Promise.allSettled when all must complete
- Set timeouts for external calls
- Use AbortController for cancellation

## Error Handling
- Use centralized error handler
- Create custom error classes
- Log errors with context (request ID, user)
- Return appropriate status codes
- Never expose stack traces in production

## Environment
- Use dotenv for local config
- Validate env variables at startup (envalid)
- Use different configs per environment
- Never commit secrets
- Use secret managers in production

## Security
- Validate all input (Zod, Joi)
- Use helmet for HTTP headers
- Rate limit APIs (express-rate-limit)
- Keep dependencies updated (npm audit)
- Use npm/yarn lockfiles

## Performance
- Use clustering for multi-core
- Enable gzip compression
- Implement caching (Redis)
- Use connection pooling
- Profile with clinic.js

---
> Converted and distributed by [TomeVault](https://tomevault.io/claim/kprsnt2) — claim your Tome and manage your conversions.
<!-- tomevault:4.0:skill_md:2026-04-15 -->

