Node.js interview questions
Show answer
Node runs your JavaScript on one main thread; a long computation blocks every other request until it finishes. Options: move work to worker threads, a background job queue, or a separate service; break work into chunks; or use native/streaming APIs. Keep request handlers doing I/O, not heavy computation.
Show answer
Wrap awaited code in try/catch (or use a helper that forwards rejected promises to the error middleware), return a clear status code and message without leaking stack traces, and log the details server-side. Distinguish expected errors (validation, 404) from unexpected ones (500), and add a process-level handler for unhandled rejections.