Interview Q&A / Node.js
Node.js interview questions
The event loop on the server, streams, modules and building APIs with Express.
Prefer rapid revision? Practise Node.js short interview answers →
- If Node.js is single-threaded, how does it handle thousands of requests at the same time?
Your JavaScript runs on one main thread, but slow work like network and file I/O is handed to the operating system or libuv's thread pool. The main thread never sits waiting; it keeps taking new requests and runs each callback when its I/O finishes.
BeginnerIn-depth3 min read - What is middleware in Express.js and how does next() work?
Middleware is a function that runs between the request arriving and the response being sent. It receives req, res and next, and it either ends the response or calls next() to pass control to the next middleware or route. Calling next(err) jumps to error-handling middleware.
BeginnerIn-depth2 min read - What is the difference between CommonJS (require) and ES modules (import) in Node.js?
CommonJS uses require and module.exports, loads files synchronously, and was Node's original system. ES modules use import and export, are the JavaScript standard, are analysed before running, and support top-level await. Node supports both.
BeginnerIn-depth3 min read - What is the difference between dependencies and devDependencies, and why do we need package-lock.json?
dependencies are packages your app needs to run in production; devDependencies are only needed while developing, testing or building. package-lock.json records the exact version of every installed package so every machine and deployment gets the same dependency tree.
BeginnerIn-depth3 min read