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. What is callback hell and how do you avoid it?

    Callback hell is deeply nested callbacks where each step lives inside the previous one, making code hard to read and handle errors in. Avoid it with named functions, promises, and async/await.

    BeginnerQuick answer1 min read
  2. What is the difference between fs.readFileSync, fs.readFile and fs.promises.readFile?

    readFileSync blocks the thread until done. readFile takes a callback and does not block. fs.promises.readFile returns a promise for use with await. In servers, prefer the non-blocking forms.

    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