Interview Q&A / Node.js

INTERVIEW Q&A · 68 QUESTIONS

Node.js interview questions

The event loop on the server, streams, modules and building APIs with Express.

  1. How do you handle errors in asynchronous Node.js code, and what is an unhandled promise rejection?

    Use try/catch around await, .catch() on promise chains, and the error-first argument in callbacks. An unhandled rejection is a promise that fails with no handler attached; since Node 15 it crashes the process by default, so every promise needs a catch somewhere.

    IntermediateIn-depth3 min read
  2. What are streams in Node.js and why would you use them for large files?

    A stream processes data in small chunks as it arrives instead of loading everything into memory at once. For a large file, streams keep memory use low and let you start sending data immediately, and pipeline() handles backpressure and errors for you.

    IntermediateIn-depth3 min read
  3. What is the difference between process.nextTick, setImmediate and setTimeout in Node.js?

    process.nextTick runs right after the current operation, before promise callbacks and before the event loop moves on. setImmediate runs in the check phase, right after I/O polling. setTimeout(fn, 0) runs in the timers phase after at least about 1 ms.

    IntermediateIn-depth3 min read