Node.js 可靠编程
下载地址
https://www.zhengdianxue.com/wp-content/uploads/skills/user_f12a44b7--self-dev-nodejs.zip将提示词发送给你的 AI 安装该 skills
请根据 https://skillhub.cn/install/skillhub.md,安装 @user_f12a44b7/self-dev-nodejs。Node.js 可靠编程技能。避免事件循环阻塞、异步陷阱、ESM 兼容问题和内存泄漏。触发词:Node.js 开发、async/await、流处理、性能优化、安全编码。
阅读全文 (展开查看完整说明)
概述
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