Why is using sync APIs in request handlers a mistake?
Because sync APIs like fs.readFileSync block the event loop for the duration of the operation. While the sync code runs, no other request can be processed. Always use async APIs like fs.readFile in request handlers.
Verify This Answer
Cross-check this information using these trusted sources:
More FAQs in Common Event Loop Mistakes That Cause Node.js Performance Issues
Blocking the event loop with heavy synchronous code. This stops all requests while the sync code runs. Always use async APIs in request handlers and offload CPU-heavy work to worker threads.
Because recursive nextTick calls run before I/O, starving the event loop. The poll phase never runs, and all connections stall. Use setImmediate instead for most deferred work, since it runs after I/O.
Because sequential await runs operations one after another, while Promise.all runs them in parallel. For multiple independent I/O-bound operations, Promise.all is often much faster since the operations run concurrently.
Still have questions?
Browse all our FAQs or reach out to our support team
