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 does util.promisify do and when is it useful?

    It converts a function that takes an error-first callback as its last argument into one that returns a promise, so older callback APIs can be used with async/await.

    BeginnerQuick answer1 min read
  3. What is the difference between Promise.all and Promise.allSettled?

    Promise.all rejects as soon as any promise rejects and gives you results only if all succeed. Promise.allSettled always waits for every promise and reports each outcome as fulfilled or rejected.

    BeginnerQuick answer1 min read