This curated guide contains the top technical interview questions and detailed architectural answers asked by top tech employers (Amazon, Microsoft, Google, PayPal, Netflix) and university external examiners for BCA, MCA, and B.Tech viva exams.
Answer: Node.js is an open-source, cross-platform runtime environment built on Google Chrome's V8 engine that executes JavaScript outside the browser. While browser JavaScript interacts with the DOM (window, document) and focuses on user interfaces, Node.js provides low-level operating system APIs (file system, TCP/HTTP network sockets, operating system processes, binary buffers) to build backend server applications.
Answer: No. JavaScript code executes on a single main thread via the V8 engine and Libuv Event Loop. However, Node.js uses a multi-threaded C++ library (Libuv) that maintains a background Thread Pool (default 4 threads) to handle blocking tasks like file I/O, DNS queries, and cryptographic hashing, and modern Node supports true multi-threading via the worker_threads module.
Answer:
1. Timers: Executes setTimeout and setInterval callbacks.
2. Pending Callbacks: Executes deferred system-level I/O callbacks.
3. Idle / Prepare: Internal Libuv subsystem tasks.
4. Poll: Retrieves new I/O events and executes I/O callbacks; blocks if empty.
5. Check: Dedicated to executing setImmediate() callbacks.
6. Close Callbacks: Executes cleanup handlers (e.g. socket.on('close')).
Note: process.nextTick() and Promise microtasks are drained between every single phase!
Answer: Backpressure occurs when a Readable stream produces data faster than a Writable stream can consume/write it, causing data to accumulate in RAM buffers. Streams handle backpressure automatically: when the internal buffer reaches its highWaterMark, writable.write() returns false, which signals the readable source to pause until the writable destination emits a drain event.
Answer: Buffer.alloc(size) fills every allocated byte with zeros, preventing sensitive data leakage. Buffer.allocUnsafe(size) allocates memory without zero-filling, which is faster but may contain old sensitive memory chunks (passwords, tokens). Unsafe buffers must be manually sanitized before exposure.
next() function in Express middleware?Answer: Express middleware functions execute sequentially in a pipeline. Calling next() passes control to the next middleware in the stack. If next() is called with an argument (e.g. next(new Error('Auth failed'))), Express immediately skips all remaining standard middleware and jumps straight to the global 4-parameter error handler.
res.send(), res.json(), and res.end()?Answer: res.end() is the low-level Node method that ends the HTTP response without setting Content-Type. res.send() is an Express method that automatically inspects data type (string, buffer, object) and sets appropriate headers (text/html, etc.). res.json() explicitly stringifies objects and guarantees Content-Type: application/json.
Answer: Use the Cluster module for scaling network I/O and web server traffic across multiple CPU cores (each worker has its own memory space and shares the listening port). Use Worker Threads for offloading CPU-intensive algorithms (image compression, cryptography, machine learning) inside a single process where threads can share memory via SharedArrayBuffer.
Answer: Avoid unbounded in-memory caches (use Redis with TTL instead), always remove event listeners when sockets or requests close, avoid unintended global variables, avoid closures holding references to large DOM/Buffer objects, and monitor memory using V8 heap snapshots and Prometheus/Grafana metrics.
Answer: A zero-downtime reload updates the running application code without dropping any user connections. The process manager starts a new worker process with the new code, waits until it successfully binds and passes health checks, directs incoming traffic to it, and only then terminates the old worker process.
Boost your server-side JavaScript proficiency by studying these closely connected core modules:
Review practical code solutions for interview lab tests.
Detailed breakdown of the most frequently asked interview topic.
Review API signatures and syntax right before your interview.