1---2name: nodejs3description: Write reliable Node.js avoiding event loop blocking, async pitfalls, ESM gotchas, and memory leaks.4---5
6## Quick Reference
7
8| Topic | File |
9|-------|------|
10| Callbacks, Promises, async/await, event loop | `async.md` |
11| CommonJS vs ESM, require vs import | `modules.md` |
12| Error handling, uncaught exceptions | `errors.md` |
13| Readable, Writable, Transform, backpressure | `streams.md` |
14| Memory leaks, event loop blocking, profiling | `performance.md` |
15| Input validation, dependencies, env vars | `security.md` |
16| Jest, Mocha, mocking, integration tests | `testing.md` |
17| npm, package.json, lockfiles, publishing | `packages.md` |
18
19## Critical Traps
20
21- `fs.readFileSync` blocks entire server — use `fs.promises.readFile`
22- Unhandled rejection crashes Node 15+ — always `.catch()` or try/catch
23- `process.env` values are strings — `"3000"` not `3000`, parseInt needed
24- `JSON.parse` throws on invalid — wrap in try/catch
25- `require()` cached — same object, mutations visible everywhere
26- Circular deps return incomplete export — restructure to avoid
27- Event listeners accumulate — `removeListener` or `once()`
28- `async` always returns Promise — even for plain return
29- `pipeline()` over `.pipe()` — handles errors and cleanup
30- No `__dirname` in ESM — use `fileURLToPath(import.meta.url)`
31- `Buffer.from(string)` — encoding matters, default UTF-8