Courses / Node.js: From First Script to Production / Chapter 1
Module 1 · Start here · Chapter 1 of 27
The Node.js Interview: Rounds, Scoring and a Study Plan
Start here. Next up: Getting Started: What Node.js Is and Running Your First Script.
Part 1 · How a Node.js round runs
The usual formats
A Node.js round is a conversation in which you show how you think about a runtime, usually with a keyboard in front of you. The formats below are the common ones, described in general. A real round is set by the team that runs it, so nothing here says what any company asks. What this chapter does is name the skills the formats share, so that you can prepare for all of them.
| Format | What you are asked to do | Where this course prepares you |
|---|---|---|
| Concept questions | Explain how something works in Node and why | the event loop, streams and modules chapters |
| Predict the output | Read a short script and say exactly what it prints | the output puzzles chapter |
| Live coding | Write a small function or endpoint while you talk | the async programming and web server chapters, and the mock |
| Debugging | Find why a snippet or a service misbehaves | the profiling, memory and advanced topics chapters |
| Take-home | Build a small API on your own time | the databases chapter and the case study |
| Production scenario | Discuss what you would do when a service is slow, leaks or drops requests | the scaling and observability chapters, and the mock |
One round may mix two of these. A common mix is a concept question that grows into code, such as "how does Node handle many connections?" followed by "write a function that fetches a list of URLs, ten at a time". The second half checks whether the first half was understanding or a memorised sentence.
What each format is testing
Concept questions test whether you hold a correct model of the runtime. The model is small: one thread runs your JavaScript, queues hold the callbacks that are waiting, and a few things run on other threads. A good answer uses those words, says what is not guaranteed, and gives an example that can be checked.
Predict-the-output questions test the same model under pressure. There is no room to bluff, because the output is one exact list of lines. They reward a habit more than knowledge: mark the synchronous lines first, then list what each line queues and in which queue, then replay the queues in the order Node empties them.
Live coding tests whether you can turn a requirement into working code and notice what the requirement left out. The signals are small: you ask what happens on bad input, you bound anything that could grow, you handle the error path, and you run the code before you call it done. Debugging adds a second skill, which is reading evidence: a latency number, a loop delay, a profile.
Take-homes and production scenarios test judgement. Judgement means naming limits and timeouts, saying what you would measure, and choosing between options with a reason. A take-home is also the one format where tidy structure, tests and a short README count, since nobody watches you write it.
A predict example, run
Here is a short script of the kind a predict round uses. Write the order of the six lines before you read the output.
console.log('A'); setTimeout(() => console.log('B'), 0); Promise.resolve().then(() => console.log('C')); (async () => { console.log('D'); await null; console.log('E'); })(); console.log('F');
predict.mjs
A D F C E B
Node 24.18.0. The same order in repeated runs.
Walk it with the habit. The synchronous lines are A, then D (the body of an async function runs at once, until its first await), then F. Three things were queued: a timer, a promise job from then, and the rest of the async function after await null, which is also a promise job. The promise jobs run before the timer. The then callback was queued first, so C comes before E. The timer prints B last.
Notice that the explanation never says "because it is async". It names the queue each line joined. That is the difference between a 2 and a 4 on the first criterion in the next lesson. The output puzzles chapter has sixteen more like this, each checked on Windows and on Linux.
Before the round starts
A few habits save minutes in any format. Say your Node version if you are asked to run code, and say that you are assuming Node 22 or later, since the module and TypeScript behaviour changed across versions. Ask whether you may run code. If you may, keep a scratch folder open, and use node --watch file.mjs so that the file runs again each time you save it.
Think aloud from the first minute. The listener cannot see your reasoning, only your words. Say what you are assuming, what you will do first, and what you would check. If you get stuck, say where: "I know the callback runs later, but I am not sure which queue" is a better answer than silence, and it gives the other person something to help with.
Finally, keep two lists in your head: what is guaranteed and what is not. The guaranteed list is long and useful: synchronous code finishes first, callbacks do not interrupt each other, and ticks and promise jobs run before the loop moves on. The short list of what varies is just as useful to name: setTimeout(fn, 0) against setImmediate in the main module is one example. Saying "that order is not guaranteed" is a correct answer, and a confident one.
Why does an explanation of a predict question name a queue instead of saying "because it is async"?
- Naming the queue gives a checkable reason for the order. "Async" does not say which callback goes first.
Which of the six formats scores production judgement most directly?
- The production scenario, and the take-home, where you choose limits, timeouts and what to measure.
What do you say when a question depends on an order that is not guaranteed?
- That the order is not guaranteed, and under what condition it varies. That is a correct answer and shows you know the runtime.
Part 2 · What gets scored: five criteria
The rubric
Interviewers score in their own ways, and the rubric here is this course's own. It is not a claim about what any employer uses. It follows the shape of public rubrics such as the Tech Interview Handbook, which name four criteria, communication, problem solving, technical competency and testing, and score each at four levels from strong no hire to strong hire. The five criteria below are tuned to Node.
| Criterion | What it covers | A 1 looks like | A 4 looks like |
|---|---|---|---|
| Runtime knowledge | what Node does underneath: the event loop and its queues, the thread pool, streams, memory | Says "Node is async" or "single-threaded" without saying what runs where; cannot name a queue or a phase | Names the queue or thread involved at each step, states the exceptions, and says what is not guaranteed |
| Async correctness | order, concurrency and failure in async code you write or read | Predicts the wrong order, forgets an await, starts unbounded work or loses an error | Predicts orders from the queues, bounds concurrency, handles every rejection and keeps results in order |
| Code quality | small readable code that refuses bad input and was run | Code does not run, or takes bad input without any check | Small functions with clear names, bad input refused with clear errors, and the code run to check it |
| Production judgement | limits, timeouts, memory, retries, measurement and shutdown | Ignores limits and failure, and guesses at performance |
Scoring a concept answer
Not every row applies to every format. A spoken concept answer is scored mostly on runtime knowledge, production judgement and communication. Code quality needs code, and async correctness needs async code. Live coding and the mock prompts use all five.
Take the question "Is Node single-threaded?". Here are two spoken answers and the scores they would earn.
| Answer | Runtime knowledge | Production judgement | Communication |
|---|---|---|---|
| A. "Yes. Node is single-threaded, so it can only do one thing at a time, and it cannot do heavy work." | 1 | 1 | 2 |
| B. "Your JavaScript runs on one thread, but a Node process has more. Files, DNS lookups and some crypto run on a pool of four threads by default, sockets use the operating system, and worker threads are for your own CPU work. I would show it with five hashes." | 4 | 3 | 4 |
Runtime knowledge1
Production judgement1
Communication2
Runtime knowledge
How the criteria relate to public ones
A public rubric with four criteria can be mapped onto the five here, so that practice in one carries over to the other. Communication keeps its name. Problem solving, which covers choosing and refining an approach, is split in two: runtime knowledge for the model of how Node works, and async correctness for applying it to code. Technical competency, which covers clean working code, becomes code quality. Testing, which covers checking typical and edge cases, is part of code quality here, because the rubric asks that the code was run, and part of production judgement, because measurement belongs there.
Production judgement is the one row with no direct match. A Node role is largely about services that must keep running, so limits, timeouts, retries and shutdown deserve a row of their own. That row is what the later chapters of this course spend most of their time on.
Two cautions about using a rubric on yourself. First, score what you did, not what you meant: if you did not say it, it does not count. Second, a 4 is not perfection, it is an answer that anticipates the next question. If a listener would have had to ask "and what about bad input?", the answer was a 3.
Why does answer A earn a 1 for production judgement?
- It gives no way to check the claim and no guidance on when work should move off the main thread, only the unexplained claim that heavy work cannot be done.
How do you tell a 3 from a 4?
- A 3 is right and clear. A 4 also answers the question the listener would have asked next, such as what happens on bad input or what is not guaranteed.
Which criterion has no direct match in a four-criterion public rubric?
- Production judgement. It exists because Node roles centre on services that must keep running.
Part 3 · A method for answering
Five steps
A method keeps a good answer from depending on a good mood. This one works for concept questions and gives a shape to the first minutes of a coding question. It has five steps, and each takes about thirty seconds when spoken.
| Step | What you do | It sounds like |
|---|---|---|
| 1. Define | Say what the thing is, in one sentence, with the exceptions that matter | "Your JavaScript runs on one thread, but a Node process uses more." |
| 2. Mechanism | Name the queue, thread or phase involved, and what it does | "Files and some crypto go to a pool of four threads; sockets use the operating system." |
| 3. Proof | Show the smallest code that proves it, and say what you expect | "Five hashes at once: four should finish together and the fifth later." |
| 4. Trade-off | Say what it costs and when another choice is better | "A bigger pool uses more memory and cores; CPU-heavy work belongs in a worker." |
| 5. Failure | Name how it breaks and how you would notice | "A synchronous hash in a handler delays every request; I would watch loop delay." |
Steps 1 and 2 earn the runtime knowledge row. Step 3 shows that the answer can be checked, which is what separates knowing from remembering. Steps 4 and 5 earn production judgement, and the whole sequence earns communication, because the listener can follow it.
The next page applies it to the question from the last lesson, with a real run for step 3.
Worked answer: is Node single-threaded?
Step 1, define. "Your JavaScript runs on one thread, the main thread, but a Node process is not only one thread." Step 2, mechanism. "The event loop runs on the main thread. libuv, the C library under Node, keeps a pool of four threads by default. File system calls, DNS lookups through dns.lookup, some crypto and compression go to that pool. Sockets do not: the operating system tells the loop when they are ready. For CPU-heavy JavaScript you start a worker thread."
Step 3, proof. "pbkdf2 is a slow password hash that runs on the pool. If I start five at once, four should run together, and the fifth should wait for a free thread." The script starts five hashes and prints when each finishes.
import { pbkdf2 } from 'node:crypto'; const start = performance.now(); for (let i = 1; i <= 5; i++) { pbkdf2('secret', 'salt', 1_000_000, 64, 'sha512', () => { const ms = Math.round(performance.now() - start); console.log(`hash ${i} done at ${ms} ms`); }); }
threads.mjs
run 1 hash 1 done at 619 ms hash 3 done at 629 ms hash 4 done at 657 ms hash 2 done at 695 ms hash 5 done at 1055 ms run 2 hash 4 done at 500 ms hash 1 done at 556 ms hash 2 done at 606 ms hash 3 done at 636 ms hash 5 done at 919 ms run 3 hash 2 done at 443 ms hash 1 done at 445 ms hash 4 done at 494 ms hash 3 done at 540 ms hash 5 done at 845 ms
Node 24.18.0 on this machine, three runs. The numbers vary on every run.
In all three runs the fifth hash finished last, well after the first four. One hash alone took 327 to 358 ms in three runs. The first four finished between 443 and 695 ms, and the fifth between 845 and 1,055 ms. That fits four threads working while the fifth waits for a free one. The times only show the shape; they are not used to compare two settings from one run.
The rest of the answer
A second small check shows that the main thread keeps running while the pool works. The script below starts the same five hashes, and a timer ticks every 50 ms on the main thread. If the hashes ran on the main thread, the ticks would stop.
import { pbkdf2 } from 'node:crypto'; let ticks = 0; const timer = setInterval(() => ticks++, 50); let left = 5; const start = performance.now(); for (let i = 0; i < 5; i++) { pbkdf2('secret', 'salt', 1_000_000, 64, 'sha512', () => { if (--left > 0) return; clearInterval(timer); const ms = Math.round(performance.now() - start); console.log(`5 hashes in ${ms} ms, ticks: ${ticks}`); }); }
ticks.mjs
5 hashes in 1020 ms, ticks: 16 5 hashes in 969 ms, ticks: 15
Node 24.18.0, two runs.
The timer ticked 16 and 15 times while the hashing took 1,020 and 969 ms, so the main thread was free. That is the proof that the work was elsewhere.
Step 4, trade-off. "The pool is shared. Files, DNS and crypto compete for the same four threads, so five slow hashes can delay an unrelated file read. Raising UV_THREADPOOL_SIZE helps only if there are cores to run the extra threads, and it must be set before the pool is first used: the Node documentation says that setting it from inside a program is not guaranteed to work. With the variable set to 8 outside the program, the last of the five hashes finished at 487 to 714 ms in three runs, against 845 to 1,055 ms with the default. For CPU-heavy JavaScript, a worker thread is the right tool, not a bigger pool."
Step 5, failure. "The danger is the opposite mistake: a synchronous call such as pbkdf2Sync in a request handler runs on the main thread and stops every request until it finishes. I would notice it as a loop delay near the latency, and I would find the call with a CPU profile." That last sentence leads straight into a follow-up question, which is the point of ending on a failure mode.
The same method on a coding prompt
For code, the steps change names but not order. Clarify what the function takes, returns and does on bad input, which is step 1. Plan the approach and name the data structure, which is the mechanism. Write the smallest version and run it, which is the proof. Then name its limits and what you would add, which is the trade-off, and say how it fails.
Concretely, for "fetch a list of URLs, ten at a time", you would say: the result shape and what counts as failure, then "a shared index and ten workers", then write it, then run it on a local server and check the counts, then say that you would add a retry with backoff and a total deadline, and that without the limit the client would open as many sockets as there are URLs. The mock chapter works this exact prompt, so try it there before you read the answer.
Which step of the method makes an answer checkable?
- Step 3, the proof: the smallest code that shows the claim, with what you expect it to print.
In the five-hash run, why does a result from one run not prove that two pool sizes differ?
- Times vary on every run, so one run can mislead. The runs here show only the shape: four finish together and the fifth waits.
What does the ticking timer in the second script prove?
- That the main thread was free while the hashes ran, so the work happened on other threads.
Part 4 · Common mistakes
Ten mistakes that cost points
The mistakes below show up across formats. Each costs points on one of the five criteria, and each has a fix you can practise. They are listed with the criterion they hit hardest.
| Mistake | Costs you | Fix |
|---|---|---|
| Saying "Node is async" without saying what runs where | Runtime knowledge | Name the queue or thread for each step |
| Calling Node single-threaded, or multi-threaded, with no qualification | Runtime knowledge | Use the define step: one thread for your JavaScript, more in the process |
| Predicting output from the order of the lines | Async correctness | List what each line queues, then replay the queues |
Starting unbounded work, such as Promise.all over a huge list | Async correctness | Bound concurrency and say the limit aloud |
Leaving a rejection unhandled or an await out | Async correctness | Trace the error path before you call code done |
| Writing code and never running it | Code quality | Run it, even once, and fix what the run shows |
| Optimising by guessing, or comparing two versions from one run | Production judgement | Measure first, repeat the run, and quote a range |
| Forgetting limits, timeouts and shutdown in a design | Production judgement |
One run decides nothing
"I made it faster" is a claim about a measurement, and one measurement is not enough. The next script times a single hash. Nothing about it changes between the three runs.
import { pbkdf2 } from 'node:crypto'; const start = performance.now(); pbkdf2('secret', 'salt', 1_000_000, 64, 'sha512', () => { console.log(`one hash: ${Math.round(performance.now() - start)} ms`); });
one.mjs
one hash: 353 ms one hash: 358 ms one hash: 327 ms
Node 24.18.0 on this machine, three runs of the same file.
The three runs gave 353, 358 and 327 ms for identical code, a spread of about 10 percent. A later session on the same machine gave 446, 480 and 489 ms for the same file, so the level itself moves from one session to the next. A change that saves 5 percent could not be seen in one run of each version. The habit is to repeat each measurement, quote the range, and compare ranges. If two ranges overlap, you have not shown a difference, and the honest answer is "I cannot tell from this".
This is also why the model answers in the mock chapter give a range over three runs, and why a number from this course always says "on this machine". The numbers belong to one computer on one day. The shape of the result is what carries over.
Stating what varies as fixed
The second mistake is subtler. Some orders in Node are not fixed, and a confident wrong answer is worse than "it depends". The classic case is setTimeout(fn, 0) against setImmediate(fn) in the main module. Which runs first depends on how long the process took to reach the loop, so the documentation says the order is not deterministic there. Inside an I/O callback the immediate always wins.
A good answer to "which prints first?" for that case is: "In the main module it is not guaranteed. If this were inside a file read callback, the immediate would run first, because the loop goes from poll to check before it returns to timers." That answer scores on runtime knowledge, because it names the phases, and on communication, because it states the boundary of what is known.
The same applies to anything that depends on timing, on the operating system, or on the Node version. The event loop chapter measured the varying case by running it twenty times and counting. When you are asked something like this and can run code, running it twenty times is a better answer than a guess.
Why is it a mistake to compare two versions from one run each?
- Runs of identical code differ by several percent, so a small difference can be noise. Repeat the runs and compare the ranges.
What is the correct answer to "which runs first, setTimeout(fn, 0) or setImmediate, in the main module?"
- That it is not guaranteed there. Inside an I/O callback the immediate runs first, because check follows poll.
Which mistake costs the most on Communication, and what is its fix?
- Going silent or coding before clarifying. Narrate from the first minute and ask the questions that matter.
Part 5 · A study plan
What the course holds, in minutes
The plan below is computed from the reading time of each chapter, which is its word count at 170 words a minute plus a minute for each scene. Reading time is the floor: typing the examples, predicting before you read the output, and redoing what you missed will take longer. Use the plan as a schedule for reading, and add your own practice on top.
| Part of the course | Chapters | Reading time |
|---|---|---|
| Basics | 9 | 276 minutes (4.6 hours) |
| Inside the runtime | 4 | 103 minutes |
| Memory and performance | 2 | 57 minutes |
| Production services | 4 | 148 minutes |
| Tests, types and operations | 4 | 114 minutes |
| Case study, puzzles and mock | 3 | 86 minutes |
| This chapter | 1 | 27 minutes |
The whole course reads in about 13.5 hours. Two plans follow, one for two weeks and one for four. The two-week plan assumes you already write Node and can skip the basics chapters. If you cannot yet say what require or await does, use the four-week plan, which starts at the beginning.
A two-week plan
Fourteen days, about an hour on most days. The order goes from how the runtime works, to code and services, to practice. The review day and the last two days hold the timed work, and their minutes are the time boxes plus about twenty minutes of scoring.
| Day | Work | Minutes |
|---|---|---|
| Day 1 | the interview chapter and async programming | 56 |
| Day 2 | event-driven code and the event loop | 49 |
| Day 3 | microtasks and the thread pool | 45 |
| Day 4 | the output puzzles and streams | 51 |
| Day 5 | the web server and the PostgreSQL API | 71 |
| Day 6 | production APIs and testing | 66 |
| Day 7 | Review: redo the puzzles you missed and explain the event loop aloud in two minutes | 30 |
| Day 8 | auth and security | 48 |
| Day 9 | caching and jobs and observability | 61 |
| Day 10 | scaling and deploying and profiling | 58 |
| Day 11 | V8 memory and advanced topics | 64 |
A four-week plan
Four weeks, five days a week, from the beginning. Each week has a theme, and the last week is for practice that ties the others together.
| Week | Chapters | Reading minutes |
|---|---|---|
| Week 1 | The interview chapter and the nine basics chapters, from getting started to advanced topics | 303 |
| Week 2 | The event loop, microtasks, the thread pool and streams, then V8 memory, profiling and the output puzzles | 181 |
| Week 3 | Production APIs, auth and security, caching and jobs, real-time, testing, TypeScript, observability, scaling and deploying | 262 |
| Week 4 | The case study rebuilt for a new domain, the mock in full, and revisiting the two lowest rows | 157 |
The last week counts the mock at 60 minutes, the sum of its five time boxes, and the same again for scoring and revisiting. Week 1 holds the most chapters but the least depth, so it is a good week to type every example and change it to see the output change.
Daily drills and one API end to end
The skills here are habits, and short daily drills suit habits better than one long session a week. Use these four, and rotate them.
- Predict, then run. Take one puzzle from the output puzzles chapter, write the exact output on paper, and only then run it.
- Explain aloud. Pick the chapter you read that day, and explain its main idea in two minutes with the five steps, as if to a friend.
- Type it, do not paste it. Type one snippet from the day, then change one thing in it and predict what changes.
- Break it. Take a working example and cause its failure on purpose, such as an unhandled rejection or a missing timeout, and read what Node reports.
Once a week, build. The case study is a full service. Rebuild it for a different domain, such as exam results on a college site, with your own tables and routes, and do it without copying: use the chapter only to check. An API you built yourself and can run is the best answer to "tell me about something you built", and it gives you real numbers to quote.
Finish with the mock, score it honestly, and repeat the prompts for your two lowest rows after revisiting the chapters the score sheet names. The plan is complete when your totals stop moving up on a repeat.
Why is the plan built from reading time and not from a promised number of hours?
- Reading time is a floor that comes from the chapters. Typing, predicting and redoing take extra time that differs between people, so you add your own.
Which plan fits someone who cannot yet explain await?
- The four-week plan, since it starts with the basics chapters. The two-week plan skips them.
What is the purpose of the weekly build?
- It gives you a working service you made yourself, with real numbers to quote, which prediction drills alone cannot give.