Node.js Skill
Best Practices
- Async/Await: Use
async/awaitover Callbacks and raw Promises. - Error Handling: Always handle Promise rejections (
.catch()ortry/catch). Unhandled rejections crash the process. - Streams: Use Streams/Pipelines for large file processing to save memory.
- Security: Use
helmetfor headers. Validate all inputs.
Common Pitfalls
- Blocking the Event Loop: CPU-intensive tasks (e.g., image resizing) on the main thread. Use Worker Threads or queues.
- Sync APIs: Using
fs.readFileSyncin HTTP handlers. Never do this.
References
Converted and distributed by TomeVault — claim your Tome and manage your conversions.