Concept:

Node.js uses a single-threaded event loop model to handle concurrency via non-blocking I/O.

Real World:

You're designing an API that downloads a large file, processes it, and returns a summary. Blocking code here will freeze the server.

Interview Questions:

Explain how the event loop phases work and what goes into each phase.

https://www.youtube.com/watch?v=1_EVy3tls0k

What happens when you use await inside a forEach() loop?

How does async/await work under the hood in the event loop?

What is the difference between setImmediate(), setTimeout(), and process.nextTick()?

Code Puzzle (Advanced):

What’s the output of the following?

console.log('start');

setTimeout(() => console.log('setTimeout'), 0);
setImmediate(() => console.log('setImmediate'));
process.nextTick(() => console.log('nextTick'));
Promise.resolve().then(() => console.log('promise'));

console.log('end');

Expected :

start
end
nextTick
promise
setImmediate // or setTimeout
setTimeout // or setImmediate depending on platform

Practice Challenges:


Node JS

STEP 2: STREAMS & BUFFERS (CORE NODE.IO)