Node.js Core & Event Loop Interview Questions (Node.js)
10 Node.js Core & Event Loop questions from the Node.js track. Read each short answer here, then open a question for the full explanation, examples, common mistakes, and sources.
- Mid-level
What are the basic phases of the event loop in Node.js and how does it handle different tasks?
The event loop goes through successive phases: timers, pending callbacks, idle/prepare, poll, check, and close callbacks, with microtasks processed between the phases.
Read the full explanation - Mid-level
What is the essential difference between process.nextTick() and setImmediate() in Node.js?
process.nextTick runs immediately after the current operation and before any later phase of the event loop, while setImmediate runs in the check phase of the event loop.
Read the full explanation - Senior
What is the role of the libuv library and the internal thread pool in Node.js and when is it used?
libuv provides the event loop and manages interaction with the operating system in a non-blocking way, and uses a thread pool (4 threads by default) for tasks the operating system cannot answer asynchronously in a native way.
Read the full explanation - Senior
How does the V8 engine manage memory between the stack and the heap in Node.js?
The stack stores call frames and local variables that hold references to values or small integers directly (Smi), while the heap stores objects, arrays, functions, and most primitive values such as strings and floating-point numbers (heap numbers), and the garbage collector manages reclaiming unused space.
Read the full explanation - Junior
What does it mean that Node.js is single-threaded and how does it handle thousands of concurrent connections?
It runs JavaScript code in one main thread, but I/O is non-blocking thanks to delegating operations to the operating system kernel and the event loop, which enables a single thread to serve thousands of connections.
Read the full explanation - Mid-level
What is the difference between uncaughtException and unhandledRejection in Node.js and what is the right action when they occur?
uncaughtException occurs on a synchronous error not caught by try/catch and the process should be terminated then, while unhandledRejection occurs when a promise fails with no catch handler.
Read the full explanation - Senior
How do you design a graceful shutdown mechanism in a Node.js app when receiving SIGTERM or SIGINT signals?
Intercept the signal, stop accepting new requests through server.close(), wait for in-flight requests to finish, close the database connections, then exit with process.exit(0).
Read the full explanation - Mid-level
How does EventEmitter work in Node.js and what causes the MaxListenersExceededWarning?
It works with the observer pattern; it emits the warning when more than 10 listeners are registered by default for the same event, which is an alert of a possible memory leak because listeners were not removed.
Read the full explanation - Mid-level
How is AbortController used to cancel asynchronous operations in modern Node.js?
AbortController provides a signal object passed to asynchronous functions to cancel the operation as soon as controller.abort() is called.
Read the full explanation - Senior
What are native addons and Node-API (N-API) and when does a developer resort to building them?
They are dynamic add-ons written in C/C++ linked to Node.js that provide a stable ABI interface (Node-API) to perform extremely fast tasks or use native system libraries.
Read the full explanation