Node.js Developer interview question · Most asked

Why is CPU-bound work a problem in Node.js and how do you handle it?

Summary

JavaScript runs on one main thread, so a long synchronous computation (large JSON parsing, image processing, crypto, heavy loops) blocks the event loop: no other requests, timers or I/O callbacks run until it finishes.

Longer Answer

Solutions: move work to worker_threads, spawn child processes, offload to a job queue or a service in another language, use async/native implementations (e.g., crypto.scrypt async, sharp for images), or break work into chunks with setImmediate. Monitor event loop lag (perf_hooks.monitorEventLoopDelay) to detect blocking.

Key Points

  • Blocks all concurrent requests
  • worker_threads for CPU tasks
  • Job queues or separate services
  • Monitor event loop delay

More most-asked Node.js Developer questions

← All Node.js Developer questions