This page pulls together the questions that come up most often in Node.js interviews, organized by theme, with answers written the way you'd actually want to explain them out loud.
Fundamentals
1. What is Node.js, exactly? A JavaScript runtime built on Google's V8 engine that lets JavaScript execute outside a browser — on a server, with access to the file system, network, and operating system, none of which a browser's JavaScript environment provides.
2. Why is Node.js described as single-threaded, and how does it still handle many requests at once? Your JavaScript code runs on one main thread. Concurrency comes from delegating I/O work (file reads, network calls, database queries) to the system through libuv, which uses a background thread pool, and notifying the main thread via the event loop once each task completes — so the single thread is never stuck waiting on any one operation.
3. What is the event loop?
The mechanism that lets Node.js's single thread stay responsive: it continuously checks whether any pending asynchronous work is ready, and runs the associated callback when it is, cycling through several phases (timers, I/O callbacks, setImmediate, and more) for as long as the process runs.
4. What's the difference between blocking and non-blocking code?
Blocking code halts execution until an operation finishes — nothing else runs meanwhile. Non-blocking code starts the operation and returns immediately, with the result handled later via a callback, Promise, or async/await, letting other code run in the meantime.
Modules and npm
5. What's the difference between core, third-party, and custom modules?
Core modules ship inside Node.js itself (fs, http). Third-party modules are published by others on npm and installed with npm install. Custom modules are files you write yourself and load with a relative require('./file') path.
6. What does package.json do?
It's a project's manifest — name, version, dependencies, scripts, and entry point — that lets npm install reproduce the exact same setup on any machine.
7. What's the difference between dependencies and devDependencies?
dependencies are needed for the app to run in production. devDependencies are only needed during development (testing tools, linters) and aren't required once the app is deployed.
Asynchronous Programming
8. What is callback hell, and how do you avoid it?
Deeply nested callbacks, each one waiting on the last, that drift the code rightward and scatter error handling across many places. Promises (with .then() chaining) and, more commonly today, async/await flatten this back into readable, top-to-bottom code.
9. What's the difference between a Promise and a callback?
A callback is a plain function handed to another function, invoked once work is done. A Promise is an object representing a future value, with .then()/.catch() methods that can be chained cleanly and share a single error handler across a whole sequence.
10. What's the difference between Promise.all() and Promise.allSettled()?
Promise.all() resolves once every Promise succeeds, but rejects immediately if even one fails. Promise.allSettled() waits for every Promise to finish regardless of outcome, returning the status (fulfilled or rejected) of each individually.
11. What does async/await actually do under the hood?
It's syntax sugar over Promises — await pauses execution of the async function (without blocking the rest of the program) until the Promise it's waiting on resolves, making asynchronous code read like ordinary synchronous code.
Core APIs
12. What is a Buffer, and why does Node.js need it? A fixed-length chunk of raw binary memory, used for data that isn't text — file bytes, network packets, image data — outside JavaScript's usual string-encoding assumptions.
13. What's the difference between readFile and readFileSync?
readFileSync blocks execution until the read finishes. readFile is non-blocking, taking a callback that runs once the read completes in the background, letting other code run in the meantime.
14. What problem do streams solve? Processing data in small chunks as it arrives, rather than loading an entire file or payload into memory at once — essential for large files or data of unknown size.
15. What's the difference between process.nextTick() and setImmediate()?
process.nextTick() runs its callback before the event loop continues to the next phase — even before Promise callbacks. setImmediate() runs after the current I/O events in that loop iteration have been processed. nextTick has higher priority, but overusing it recursively can starve the rest of the event loop.
Building Applications
16. What does middleware mean in the context of a framework like Express? A function that runs during the request-response cycle, with access to the request and response objects and the ability to modify them, end the cycle, or pass control to the next middleware — used for things like logging, authentication, and parsing request bodies.
17. What's the difference between spawn() and fork() in the child_process module?
spawn() runs any external command and streams its output. fork() is specifically for launching another Node.js script, with a built-in message-passing channel (IPC) between parent and child.
18. How would you handle CPU-intensive work in a Node.js app without freezing the server?
Offload it to a separate process (via child_process or worker threads) rather than running it directly on the main thread, since heavy synchronous computation blocks the event loop and stalls every other request until it finishes.
Security and Practical Concerns
19. Why shouldn't you hash passwords with a plain SHA-256 hash? Plain hashes are designed to be fast, which is exactly the wrong property for password storage — it lets an attacker try billions of guesses per second against a stolen hash. Passwords need a deliberately slow, salted algorithm like bcrypt or scrypt.
20. What's the purpose of environment variables in a Node.js app? Keeping configuration (database URLs, API keys, secrets) out of source code, so different values apply automatically across local development, staging, and production without changing a single line of code.
A closing note on interview prep
Memorizing answers word for word is far less useful than actually being able to explain why something works the way it does — an interviewer probing a follow-up question will notice the difference immediately. Building a few small projects (the next page has ideas) and running into these exact problems firsthand is worth more than reading through this list twice.