๋ณธ๋ฌธ์œผ๋กœ ๊ฑด๋„ˆ๋›ฐ๊ธฐ
ๅฐ้พ™่™พๅฐ้พ™่™พAI
๐Ÿค–

NodeJS

Avoid common Node.js mistakes โ€” event loop blocking, async error handling, ESM gotchas, and memory leaks.

ไธ‹่ฝฝ3.8k
ๆ˜Ÿๆ ‡5
็‰ˆๆœฌ1.0.1
AI ๆ™บ่ƒฝไฝ“
ๅฎ‰ๅ…จ้€š่ฟ‡
๐Ÿ’ฌ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

TopicFile
Callbacks, Promises, async/await, event loopasync.md
CommonJS vs ESM, require vs importmodules.md
Error handling, uncaught exceptionserrors.md
Readable, Writable, Transform, backpressurestreams.md
Memory leaks, event loop blocking, profilingperformance.md
Input validation, dependencies, env varssecurity.md
Jest, Mocha, mocking, integration teststesting.md
npm, package.json, lockfiles, publishingpackages.md

Critical Traps

  • fs.readFileSync blocks entire server โ€” use fs.promises.readFile
  • Unhandled rejection crashes Node 15+ โ€” always .catch() or try/catch
  • process.env values are strings โ€” "3000" not 3000, parseInt needed
  • JSON.parse throws on invalid โ€” wrap in try/catch
  • require() cached โ€” same object, mutations visible everywhere
  • Circular deps return incomplete export โ€” restructure to avoid
  • Event listeners accumulate โ€” removeListener or once()
  • async always returns Promise โ€” even for plain return
  • pipeline() over .pipe() โ€” handles errors and cleanup
  • No __dirname in ESM โ€” use fileURLToPath(import.meta.url)
  • Buffer.from(string) โ€” encoding matters, default UTF-8

ๅฆ‚ไฝ•ไฝฟ็”จใ€ŒNodeJSใ€๏ผŸ

  1. ๆ‰“ๅผ€ๅฐ้พ™่™พAI๏ผˆWeb ๆˆ– iOS App๏ผ‰
  2. ็‚นๅ‡ปไธŠๆ–นใ€Œ็ซ‹ๅณไฝฟ็”จใ€ๆŒ‰้’ฎ๏ผŒๆˆ–ๅœจๅฏน่ฏๆก†ไธญ่พ“ๅ…ฅไปปๅŠกๆ่ฟฐ
  3. ๅฐ้พ™่™พAI ไผš่‡ชๅŠจๅŒน้…ๅนถ่ฐƒ็”จใ€ŒNodeJSใ€ๆŠ€่ƒฝๅฎŒๆˆไปปๅŠก
  4. ็ป“ๆžœๅณๆ—ถๅ‘ˆ็Žฐ๏ผŒๆ”ฏๆŒ็ปง็ปญๅฏน่ฏไผ˜ๅŒ–

็›ธๅ…ณๆŠ€่ƒฝ