Node.js Interview Questions for Backend and Full-Stack Developers | OfferBull

Node.js Interview Questions for Backend and Full-Stack Developers
The process is pegged at 100% CPU. The health check is still green. Incoming requests have started to queue. They ask what you look at first.
If you say “Node is single-threaded” and stop, you haven’t answered. They want to know whether JavaScript on the event loop is busy, whether the libuv threadpool is starved, or whether you actually need another process.
That’s what Node.js interview questions feel like on a backend or full-stack loop. Server-side Node: libuv, streams, cluster, worker threads, Express, and the failure modes that show up in production. Language fundamentals (closures, this, the microtask primer) live in JavaScript interview questions. Read that first if those still wobble, then come back here. For how the rounds fit together, use backend engineering interviews or the full-stack preparation guide.
Samples below are made up. Say them out loud. A fluent blog answer is not the same as explaining a blocked event loop under a clock.
Event loop and libuv
A short recap, then we leave the language-primer version alone. JavaScript still runs on one main thread. Work that finishes in the host gets queued, and the loop feeds it back to that thread. Microtasks still run after the current stack, before the next timer or I/O callback. If you need the Promise-versus-setTimeout(0) walkthrough, it’s in the JavaScript post. A Node interview usually starts one layer down: Node’s loop is built on libuv, and some work is not on the JavaScript thread at all.
I wouldn’t pretend I memorized the C. The phases I can draw in a room are enough:
- timers:
setTimeoutandsetIntervalcallbacks whose delay has elapsed - pending callbacks: a few deferred I/O callbacks (system-specific; I mention them and move on)
- poll: wait for incoming I/O, then run those callbacks. This is where the loop can sit if there’s nothing else to do
- check:
setImmediate - close callbacks: things like a socket
'close'
Between those pieces of work, Node also drains process.nextTick and promise microtasks. nextTick is not a libuv phase. It runs after the current JavaScript finishes, before the loop moves on, and it has higher priority than Promise.then. A recursive nextTick can starve I/O. I wouldn’t open with setImmediate versus setTimeout(0) trivia. If they ask: in the main module the order is not guaranteed; inside an I/O callback, setImmediate usually runs first.
The threadpool is the part people skip, and it’s the part that explains a lot of “the event loop looks idle but the box is slow” stories. libuv has a pool of worker threads. The default size is 4. You can change it with UV_THREADPOOL_SIZE, preferably before the process starts heavy work. Many asynchronous fs calls go there. So do several crypto operations (pbkdf2, scrypt, randomBytes, randomFill) and dns.lookup(), which uses getaddrinfo. dns.resolve() is different: it uses c-ares and does not take a threadpool slot. If you fire twenty concurrent pbkdf2 password hashes or a burst of large fs.readFile calls, those jobs queue behind four workers even if the JavaScript thread is doing nothing.
That is also why this sentence needs two halves. The JavaScript event loop is single-threaded. Node can still use threads: libuv’s pool for those C++ tasks, and worker_threads for your own JavaScript. CPU-heavy JavaScript (a huge JSON.parse, a tight loop, a painful regex on a giant string) still blocks the loop, because it never leaves the JavaScript thread. fs.readFileSync and crypto.pbkdf2Sync block it too, for the more obvious reason that they don’t return until the work is done.
Spoken: “I’d split ’the event loop is blocked’ from ’the threadpool is saturated.’ Sync I/O and heavy JavaScript block the loop. Async fs and pbkdf2 usually occupy the pool, default four threads. dns.lookup uses the pool; dns.resolve does not. If the JS thread is busy, adding more libuv threads will not help.”
Q: A login endpoint used to be fine, then p95 jumped after traffic increased. The handler is async and uses pbkdf2. Why might that happen?
A: “I’d look at threadpool queueing first. Four workers, a CPU-heavy hash, and a burst of logins will stack up. I’d confirm with metrics, then consider a slightly larger pool, a cheaper hash settings review with security, or moving the hash off this process. I wouldn’t ‘fix’ it by wrapping the same work in another async function.”
Streams, cluster, and worker threads
Streams exist so you don’t pull a huge file or a huge response into memory. The four types I name are readable, writable, duplex, and transform. fs.createReadStream is readable. An HTTP response is writable. A socket is duplex. A zlib gzip stream is transform.
.pipe() is the usual way to connect them, and it handles backpressure: if the writable side is slow, the readable side should pause instead of filling RAM. In older code you may still see pause() and resume(). If you write to a stream by hand, respect writable.write() returning false and wait for 'drain'.
The interview version is concrete. Exporting a 4 GB CSV with fs.readFile is a way to blow the process. A read stream, maybe a transform, and a write stream will keep memory flat. The pitfall: streams are EventEmitters. If a stream errors and nobody is listening for 'error', Node can take down the process. .pipe() does not attach a complete error handler for you. I’d listen for 'error' on each stream, or use pipeline() so errors and cleanup are handled together.
cluster and worker_threads get mixed up with the threadpool, so I separate them on the board.
cluster runs more than one Node process, typically one per CPU, and they can share a listening port. On most platforms the primary process distributes incoming connections. This is how you scale an HTTP service across cores when one process is not enough. Workers don’t share memory, except over IPC. Each worker still has its own event loop, so a CPU-heavy request still blocks that worker. cluster does not make a synchronous JSON.parse of a huge payload non-blocking.
worker_threads run JavaScript on additional threads in the same process. Each worker has its own V8 isolate and event loop. You talk with postMessage, and you can share memory with a SharedArrayBuffer when you need it. This is the right tool for CPU work you want off the main thread without a full process: a heavy parse, a report you don’t want stalling requests. It is not the libuv threadpool. The pool is for a fixed set of C++ operations. Workers are for your JS.
Spoken: “cluster is multiple processes, good for taking more HTTP traffic on one machine. worker_threads is extra JS threads for CPU work. The libuv pool is a third thing, and I wouldn’t use cluster to hide a blocking function I should have moved or made async.”
A stream is a pipeline. If the right side is slow, the left side has to pause.
Express, API design, and error handling
Express is still the framework most interviewers reach for. I’d mention Fastify or whatever the JD actually uses in one sentence, then work in Express unless they stop me. The ideas transfer: middleware order, how errors get to a single handler, and how you design the HTTP API.
Middleware runs in the order you mount it. Parse the body before a handler that reads req.body. Authenticate before a route that needs a user. Validation before the business logic. The error handler comes last, and it has to be the four-argument signature (err, req, res, next) or Express will not treat it as an error middleware.
Async error handling is a common trip. In Express 4, a rejected promise from an async route handler is not forwarded for you. The request can hang, or you get an unhandled rejection, depending on what else is listening. You must call next(err) or wrap the handler. Express 5 does forward rejected promises to the error middleware. If I don’t know the version in the room, I still forward the error on purpose and I still keep one centralized error handler. That handler logs the real error, returns a safe message, and does not dump a stack trace to the client in production. Status codes should mean something: 400 for a bad request you already validated, 401 vs 403 when auth is involved, 404, 409, 429, 5xx for your failures.
I’d also put timeouts on incoming requests and on outbound calls. An upstream that never returns is a leaked socket. Validate input; don’t trust req.body or query strings. A basic helmet setup is a baseline, not a security audit. I mention authentication and authorization as two checks, then I stop unless they want to go deeper.
REST questions in this room are usually practical. PUT and DELETE should be idempotent: two identical requests leave the same state. POST usually is not. Pagination should be explicit, with a cursor or a limit I can defend. Versioning can be a prefix (/v1) or a header; I’d pick one and say how old clients get a sunset. If they want more API discussion, use the API design interviews post. If the follow-up is “this service is now a traffic problem,” I’d borrow the clock from the system design interview template instead of turning an Express question into a half-finished architecture.
Spoken: “Middleware order is the design. I’d parse, authenticate, validate, then handle. Errors go to one four-argument middleware. I wouldn’t leak stacks. If the handler is async, I make sure a rejection actually reaches that middleware, because Express 4 will not do it for me.”
Scenes you should be able to talk through
These are the ones I practice as short spoken answers, not essays.
Practice the blocked-event-loop answer out loud. The notes can stay as empty boxes; the words have to come from you.
The event loop is blocked. Requests pile up. CPU is high, or sometimes CPU is low and nothing is moving. “I’d check for sync fs or crypto first, then a hot function on the main thread: a large JSON parse, a regex, a long loop. If CPU is low and latency is high, I look at the threadpool and at outbound calls with no timeout. A CPU profile beats guessing.”
Stream a large export. “I would not readFile the whole thing. Read stream, transform if I need to shape rows, write stream to the response. I’d set the right content type, listen for errors on every stream, and use pipeline so a client abort actually destroys the source. I’d also think about backpressure so a slow download doesn’t inflate memory.”
One Node process is pegged at 100% CPU. “Is it one request or all traffic? One request points to blocking JavaScript or a pathological input. All workers at 100% can just be load, which is when cluster or more machines help. One core pegged and the others idle often means I never scaled out. If the work is CPU in JS, I’d move it to worker_threads or a job queue, not hide it behind another await.”
If the conversation shifts into locks or shared memory, keep concurrency and multithreading interview questions in mind, and stay honest: the main thread is still one JS thread, even when the pool and the workers are busy. Shops that also interview in Java or Python may want a comparison with a thread-per-request runtime. That’s fine; don’t mix the facts. Java for experienced developers, Spring Boot, and Python interview questions are the companions, not something to dump into a libuv answer.
Three different kinds of ’threads.’ Mixing them up is the usual wrong answer.
Night-before drill
I’d run these out loud, timer on:
- JavaScript is single-threaded; libuv and
worker_threadsare how Node still uses threads - Phases I would actually draw: timers, poll, check, close
- Threadpool default of 4, what goes there,
dns.lookupvsdns.resolve - Why heavy JS and
*SyncAPIs block the loop, and why more pool threads won’t fix that - Streams: four types, backpressure,
pipelineand'error' - cluster vs
worker_threads, and why neither is the libuv pool - Express middleware order, async errors, one error handler, no stack traces in production
- One of the three scenes: blocked loop, large export, or a process at 100% CPU
If two of them wobble, repeat those two.
Practicing with OfferBull
A diagram in a blog will not train the pause before you say “it’s single-threaded.”
OfferBull is an AI mock interview app for iOS and Android. A voice interviewer asks questions aloud. You answer by speaking. Paste a Node.js, backend, or full-stack job description, or upload a resume, for tailored questions. Follow-ups based on what you said and what’s on the resume. While you practice, you get answer suggestions and STAR structures. English and Chinese. It’s for rehearsal before the interview, not a helper during one.
FAQ
Do I have to memorize every libuv phase?
No. Timers, poll, check, and close are enough, plus where setImmediate sits. The threadpool question is usually more useful than idle and prepare.
Is cluster enough to scale Node? It helps you use more than one core on a single machine. It does not fix blocking JavaScript, and it is not a substitute for more machines or a queue. I’d treat it as one step, not the architecture.
Should I use Express or Fastify in the interview? Use what the job uses if you know it. Otherwise Express is a safe default. You can say you’d be comfortable with Fastify because the middleware and error-handling ideas transfer.
When do I reach for worker_threads?
When I have CPU-bound JavaScript I don’t want on the request thread, and the work fits in-process. Jobs that should survive a restart belong on a queue.
Will they ask me to write a stream from scratch?
Sometimes a small Readable or Transform is enough. More often they want you to use pipeline, handle errors, and not load a huge file into RAM.
Practice This Out Loud
Tonight, talk through a blocked event loop in 60 seconds, then cluster versus worker_threads in 60 more, with no notes. Then walk an Express request from middleware to the error handler, including what happens if an async route rejects. Record it. On playback, listen for “single-threaded” used as a complete answer. Then run the same scenes in a voice mock that pushes back, and close the app before any real interview. → Practice Now
Take Control of Your Career Path:
- Official Site: www.offerbull.net/mock-interview
- iOS App: Download for iPhone/iPad
- Android App: Download for Android