DEV Community

Akash Gupta
Akash Gupta

Posted on

15 Node.js Interview Questions You Should Be Able to Answer (2026)

Prepping for a Node.js interview? Here are 15 questions that come up again and again — with short, to-the-point answers. If you can explain these clearly, you're in good shape.

Basics

1. What is Node.js?
A runtime to run JavaScript outside the browser (built on V8). It's event-driven and non-blocking — great for I/O-heavy apps like APIs and real-time servers.

2. Is Node.js single-threaded?
Your JS runs on one main thread, but Node offloads heavy I/O to libuv's background thread pool. So it feels single-threaded but uses multiple threads under the hood.

3. CommonJS vs ES Modules?
CommonJS uses require/module.exports (synchronous, classic). ES Modules use import/export (modern standard, async, tree-shakeable). Enable ESM via "type":"module" or .mjs.

Event loop & async

4. What is the event loop?
The mechanism that lets single-threaded Node handle many operations at once — it runs callbacks for completed async tasks (timers, I/O) when the call stack is empty.

5. setTimeout vs setImmediate?
setImmediate runs in the "check" phase; setTimeout(fn,0) in the timers phase. Inside an I/O callback, setImmediate always fires first.

6. What is async/await?
Syntactic sugar over Promises so async code reads like sync code. An async function returns a Promise; await pauses until it settles. Handle errors with try/catch.

7. Promise.all vs allSettled vs race vs any?
all: rejects on first failure. allSettled: waits for all, reports each. race: first to settle wins. any: first success wins, rejects only if all fail.

8. How do you handle CPU-intensive tasks?
Offload them — worker_threads for parallel CPU work, child processes, or the cluster module to use all cores. Never block the single JS thread.

Modules & core

9. What are streams?
They process data in chunks instead of loading it all into memory — ideal for large files/network. Types: Readable, Writable, Duplex, Transform.

10. How does require() caching work?
The first require() runs the module and caches its exports. Later requires return the cache — so top-level module code runs only once.

Express & REST

11. What is middleware?
A function with (req, res, next) that runs during the request-response cycle. It can read/modify req/res, end the response, or call next() to pass control on.

12. What are the key REST principles?
Resources identified by URLs (nouns), standard HTTP methods (verbs), stateless requests, and meaningful status codes.

Auth & security

13. How does JWT auth work?
On login the server signs a token (header.payload.signature). The client sends it on each request; the server verifies the signature. The payload is only Base64-encoded — never put secrets in it.

14. How should you store passwords?
Never plain text. Hash with a slow, salted algorithm like bcrypt, and compare with bcrypt.compare on login — you never decrypt the stored hash.

Performance

15. How do you scale a Node app?
Use the cluster module (or PM2) to use all CPU cores, cache with Redis, add DB indexes, avoid blocking the event loop, and paginate large responses.


Want the full set? I wrote a complete 64-question guide (beginner → advanced, with English/Hinglish) here:
👉 https://asbackendinstitute.com/blog/nodejs-interview-questions/top-60-nodejs-interview-questions

What question do you always get asked in Node interviews? Drop it below 👇

Top comments (1)

Some comments may only be visible to logged-in visitors. Sign in to view all comments.