Model answers for 4 Node.js questions
Typical round: runtime concepts, API design, a debugging scenario
Q: Node.js is single-threaded. How does it handle many requests? A: JavaScript runs on one thread, but I/O like network and disk is handed to the OS or libuv's thread pool. While that work happens, the event loop keeps serving other requests and runs callbacks when results return. CPU-heavy work blocks everyone, so it goes to worker threads or a separate service.
Q: How does Express middleware work? A: Middleware are functions (req, res, next) run in order. Each can modify the request, end the response, or call next() to pass control. Error-handling middleware has four arguments and is registered last.
Q: When would you use streams? A: For large data such as file uploads, CSV exports or proxying, so you process chunks instead of loading everything into memory. pipe() or pipeline() also handles backpressure.
Q: How do you handle errors in async code? A: Use try/catch with async/await and a central error middleware, reject with Error objects, never leave promises unhandled, log with context, and return safe messages to clients.