๐ค
NodeJS
Avoid common Node.js mistakes โ event loop blocking, async error handling, ESM gotchas, and memory leaks.
ๅฎๅ
จ้่ฟ
๐ฌPrompt
ๆ่ฝ่ฏดๆ
name: NodeJS slug: nodejs version: 1.0.1 description: Write reliable Node.js avoiding event loop blocking, async pitfalls, ESM gotchas, and memory leaks. metadata: {"clawdbot":{"emoji":"๐","requires":{"bins":["node"]},"os":["linux","darwin","win32"]}}
Quick Reference
| Topic | File |
|---|---|
| Callbacks, Promises, async/await, event loop | async.md |
| CommonJS vs ESM, require vs import | modules.md |
| Error handling, uncaught exceptions | errors.md |
| Readable, Writable, Transform, backpressure | streams.md |
| Memory leaks, event loop blocking, profiling | performance.md |
| Input validation, dependencies, env vars | security.md |
| Jest, Mocha, mocking, integration tests | testing.md |
| npm, package.json, lockfiles, publishing | packages.md |
Critical Traps
fs.readFileSyncblocks entire server โ usefs.promises.readFile- Unhandled rejection crashes Node 15+ โ always
.catch()or try/catch process.envvalues are strings โ"3000"not3000, parseInt neededJSON.parsethrows on invalid โ wrap in try/catchrequire()cached โ same object, mutations visible everywhere- Circular deps return incomplete export โ restructure to avoid
- Event listeners accumulate โ
removeListeneroronce() asyncalways returns Promise โ even for plain returnpipeline()over.pipe()โ handles errors and cleanup- No
__dirnamein ESM โ usefileURLToPath(import.meta.url) Buffer.from(string)โ encoding matters, default UTF-8
ๅฆไฝไฝฟ็จใNodeJSใ๏ผ
- ๆๅผๅฐ้พ่พAI๏ผWeb ๆ iOS App๏ผ
- ็นๅปไธๆนใ็ซๅณไฝฟ็จใๆ้ฎ๏ผๆๅจๅฏน่ฏๆกไธญ่พๅ ฅไปปๅกๆ่ฟฐ
- ๅฐ้พ่พAI ไผ่ชๅจๅน้ ๅนถ่ฐ็จใNodeJSใๆ่ฝๅฎๆไปปๅก
- ็ปๆๅณๆถๅ็ฐ๏ผๆฏๆ็ปง็ปญๅฏน่ฏไผๅ