Skip to content
CompanyBenchCompanyBench

Node.js interview questions and answers

Node.js interview questions with answers on the event loop, async patterns, modules, Express, streams and performance, for freshers and experienced roles.

Questions on asynchronous programming, the event loop, modules, Express.js, streams and performance, with short model answers. Useful for candidates preparing and for interviewers screening backend developers. Level: intermediate to advanced.

Core concepts

What is Node.js and how does it work?

Node.js is a JavaScript runtime built on Chrome's V8 engine. It uses an event-driven, non-blocking I/O model, which suits scalable network applications.

What is the event loop in Node.js?

The event loop is the mechanism that handles asynchronous callbacks. It makes I/O non-blocking by handing operations off to the background and running their callbacks when they complete.

What is the difference between `require` and `import`?

`require` is CommonJS and was the original module system. `import` is ES module syntax, supported in modern Node.js when you set `"type": "module"` or use `.mjs` files.

What is npm and how is it used?

npm is the Node Package Manager. It manages a project's dependencies, scripts and packages, and is used to install, update and publish modules.

Async behaviour and timing

What is the purpose of `process.nextTick()`?

It schedules a callback to run in the same phase of the event loop, before any I/O or timers. Use it to defer work until the current call stack has cleared.

What is the difference between `setImmediate()` and `setTimeout(fn, 0)`?

`setImmediate()` runs its callback in the check phase, after I/O events. `setTimeout(fn, 0)` runs in the timers phase. Which fires first depends on which phase the event loop is in when they are scheduled.

Frameworks, data and performance

What is Express.js and why is it used?

Express.js is a lightweight web framework for Node.js. It simplifies routing, middleware and server logic.

Explain streams in Node.js.

Streams read or write data sequentially. The four types are Readable, Writable, Duplex and Transform. They handle large data efficiently because nothing has to be loaded into memory all at once.

What is the difference between `fs.readFile()` and `fs.createReadStream()`?

`fs.readFile()` loads the whole file into memory before returning. `fs.createReadStream()` reads it in chunks, which is the right choice for large files.

How can you improve performance in a Node.js application?

Use clustering and asynchronous code, add caching and avoid blocking operations. Tools such as `pm2` for process management and `clinic.js` for profiling help find bottlenecks.

Hiring? See hire Node.js developers and Node.js developer salary in India. Looking for work? Browse remote Node.js developer jobs.