Node.js Interview Questions and Answers
Node.js interviews revolve around one idea: a single thread running an event loop. You are expected to explain the phases of the loop, the difference between process.nextTick, microtasks and timers, why blocking the loop is dangerous, and how callbacks, promises and async/await relate.
Beyond the loop, expect streams and backpressure, the cluster and worker-thread modules, memory leaks, error handling in async code, security basics (injection, rate limiting, dependency risk) and how you would structure and scale an Express or Fastify service. The answers below include runnable examples.
Questions
- What is Node.js?
- Is Node.js single-threaded or multi-threaded?
- What is V8?
- What is libuv?
- What is npm?
- What is the difference between `node index.js` and running in the REPL?
- What are globals in Node.js?
- What is `process` in Node.js?
- What is `process.argv`?
- What is `process.env`?
- What is the difference between `__dirname` and `process.cwd()`?
- What is `NODE_ENV` used for?
- How do you exit a Node process?
- What is the difference between Node.js and the browser JavaScript environment?
- What are the different types of Node.js applications?
- What is a callback in Node.js?
- What is the error-first callback pattern?
- What is callback hell and how do you avoid it?
- What is the difference between synchronous and asynchronous functions in Node?
- What is `Buffer` in Node.js?
- What is the global object in Node vs the browser?
- Why is Node.js good for I/O-bound tasks but not CPU-bound tasks?
- What is the `console` module?
- What is the difference between `stdout` and `stderr`?
- How do you read user input from the command line?
- What is the module wrapper function in Node?
- What is `globalThis`?
- How does Node.js handle concurrency without multiple threads for JS?
- What is the difference between `setTimeout(fn, 0)` and `setImmediate(fn)`?
- What is `process.nextTick()`?
- What are the phases of the Node.js event loop?
- What is the difference between CommonJS and ES Modules?
- How do you enable ES Modules in Node?
- What is the `node:` protocol in imports?
- What is the difference between `module.exports` and `exports`?
- How does `require` resolve a module?
- What is the module cache?
- What is a circular dependency and how does Node handle it?
- What is the difference between `require` and `import`?
- What are Worker Threads?
- When would you use Worker Threads vs Child Processes vs Cluster?
- What is the difference between blocking and non-blocking code in practice?
- What is `process.hrtime()` / `performance.now()` used for?
- How do you handle uncaught exceptions?
- What is the difference between `process.on('exit')` and `process.on('beforeExit')`?
- What are signals like SIGINT and SIGTERM?
- What is graceful shutdown and why does it matter?
- How does garbage collection work in Node/V8?
- What is a memory leak in Node and how do you detect it?
- What is the maximum heap size in Node and how do you change it?
- What is the difference between `Buffer.alloc` and `Buffer.allocUnsafe`?
- What is the difference between `path.join` and `path.resolve`?
- What is the `util` module used for?
- What does `util.promisify` do?
- What is the difference between `dependencies` and `devDependencies`?
- What is semantic versioning (semver)?
- What is `package-lock.json`?
- What is the difference between `npm install` and `npm ci`?
- What are npm scripts?
- What is `npx`?
- What is the difference between local and global npm installs?
- What is `engines` in package.json?
- What are peerDependencies?
- How do you create a custom global module/binary?
- How does Node handle unhandled promise rejections?
- What is the `os` module?
- What is the difference between `fs.readFile` and `fs.createReadStream`?
- What is the purpose of `Buffer.concat`?
- What is the difference between `null` and `undefined` handling in Node config?
- How do you profile CPU usage of a Node application?
- What is a module in Node.js?
- What are the three types of modules in Node?
- How do you export multiple values from a module?
- What happens when you `require` a JSON file?
- How do you import JSON in ES Modules?
- What is the difference between named and default exports?
- How do you re-export from another module?
- What is a barrel file and what is its downside?
- How does Node find `node_modules`?
- What is the difference between `require('./x')` and `require('x')`?
Related
- React interview questions
- Microservices interview questions
- SQL interview questions
- Practice coding problems online
Frequently asked questions
What is the event loop in Node.js?
It is the mechanism that lets a single thread handle many connections: it runs callbacks from queues in phases (timers, pending, poll, check, close) and drains microtasks between them, handing slow work to the operating system or a thread pool.
When should I use worker threads or cluster?
Use cluster to run several processes that share a port and use all CPU cores for I/O-heavy servers. Use worker threads for CPU-heavy work inside one process so the event loop is not blocked.
What Node.js topics are asked at senior level?
Scaling and observability, memory leaks and profiling, streams and backpressure, graceful shutdown, security hardening and designing resilient services.