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 (3)
async/await is syntax sugar for generators, not promises.
async and generator functions are very expensive computing operations, since each invocation of await and yield (that's the same thing), it makes JS cache the entire execution context until it's resumed and can handle the next yield or await. So, if performance is a critical thing for your project, you may avoid async/await.
You can see that the algorithms of async and generator functions look similar
tc39.es/ecma262/#sec-asyncblockstart
tc39.es/ecma262/#sec-generatorstart
Appreciate the deep dive 🙏 — you're right that the control flow of async/await desugars into a generator-style state machine (the old co library literally faked async using generators + promises).
Two nuances I'd gently push back on though:
It's not "generators, not promises" — it's both. An async function always returns a Promise, and await only operates on promises/thenables (it queues the continuation as a microtask). The generator part is the how; promises are the what.
"Very expensive / avoid for performance" is too strong for most cases. Since V8's 2018 async/await rewrite, it's heavily optimized and basically on par with hand-written promise chains for I/O-bound work — which is the only place you'd use it anyway. For CPU-hot loops you wouldn't reach for async at all. For 99% of apps, readability wins and the overhead is noise.
Solid spec links though — the async↔generator similarity is a genuinely underrated mental model.
Some comments may only be visible to logged-in visitors. Sign in to view all comments.