nodejs
Installation
SKILL.md
Node.js Conventions
Module System
- Prefer ESM (
import/export) — set"type": "module"inpackage.json - In ESM, use
import.meta.urlfor the module URL. For local directory paths,import.meta.dirnameis available onfile:modules since Node v20.11.0 / v21.2.0; on older supported versions, derive the path withfileURLToPath(import.meta.url)andpath.dirname(). The dirname version requirement does not apply toimport.meta.url. See Node ESM documentation. - For CJS interop, use
createRequire(import.meta.url)when importing CJS-only packages - Follow project convention — if the project uses CJS, stay consistent
Async Patterns
async/awaitover callbacks — use promise-based APIs (fs/promises,timers/promises)- Handle rejections at the responsible boundary — let awaited failures propagate to the existing caller or framework error handler. Catch locally for recovery, cleanup, or useful context, not just to rethrow. Detached promises need an explicit error handler.
Promise.allfor bounded concurrent work — parallelize independent operations within connection, rate, memory, and file-handle limits. For large or unbounded collections, use the project's bounded worker/batching pattern; do not launch every operation at oncePromise.allSettledwhen all results are needed regardless of individual failures- Don't mix async paradigms — don't mix callbacks with promises/async-await in the same flow. Using
.catch()for inline error transformation withawaitis fine - Convert callback APIs — use
util.promisifyto wrap callback-only packages into promises