Skip to content
tezvyn:

Top 30 Nodejs Interview Questions and Answers

30 multiple-choice questions on Nodejs, drawn from 30 bites out of the 179 tagged Nodejs on Tezvyn. Answer them here or read straight down. Every question carries the correct option, why it is correct, and a link to the bite it came from.

30 questions. Pick an answer, or open “Show the answer” to read it.

Answers are graded in your browser. Nothing is saved, and no XP or streak is earned here. The app keeps score.

  1. Question 1 of 30

    Which statement best describes how Node.js handles I/O for thousands of concurrent connections?

    Show the answer

    Answer: a · Network sockets are watched by the OS, while blocking tasks like DNS and file reads use a small internal thread pool.

    Node.js relies on the OS kernel to monitor network sockets and notify the event loop when data arrives, while delegating blocking operations like DNS and some file system work to a limited internal thread pool. Distractor D is tempting because Node is famous for non-blocking I/O, but it wrongly assumes every I/O operation can run without thread assistance.

    Read the full bite: How does Node.js handle thousands of connections on one thread?

  2. Question 2 of 30

    What is the primary function of the V8 engine within environments like Chrome or Node.js?

    Show the answer

    Answer: c · To translate JavaScript code into native machine code for fast execution.

    V8's core role is to compile JavaScript into native machine code, enabling high-performance execution. While environments like Node.js provide APIs for interactions (option D), V8 itself is solely the engine responsible for processing the JavaScript code.

    Read the full bite: V8: The Engine Powering Chrome and Node.js

  3. Question 3 of 30

    In which event loop phase do the majority of completed I/O callbacks, such as a finished network read, actually execute?

    Show the answer

    Answer: d · The poll phase, which retrieves and runs I/O completions

    The poll phase retrieves new I/O events and executes most of their callbacks. The timers phase only handles elapsed setTimeout/setInterval, not I/O completion.

    Read the full bite: Order of the Node.js event loop phases

  4. Question 4 of 30

    For which type of task would Node.js's event-driven model, relying on EventEmitter, typically be least effective?

    Show the answer

    Answer: a · Performing intensive image manipulation or video encoding.

    The event-driven model is least effective for CPU-bound tasks like image manipulation because they block the single-threaded event loop. It excels at I/O-bound tasks such as network requests, database queries, and file operations.

    Read the full bite: Node.js Events and the EventEmitter

  5. Question 5 of 30

    When both are scheduled from inside a completed fs I/O callback, which runs first and why?

    Show the answer

    Answer: c · setImmediate, because the check phase follows poll in the same iteration

    From within an I/O callback the loop is in poll, so the next phase is check, making setImmediate fire before the timers phase comes around again. setTimeout(0) waits for the next iteration.

    Read the full bite: nextTick vs setImmediate vs setTimeout(fn, 0)

  6. Question 6 of 30

    Why does wrapping a heavy synchronous computation in an async function fail to keep a Node server responsive?

    Show the answer

    Answer: a · The computation is still synchronous and never yields the single JS thread

    async/await only helps when there is an awaited asynchronous boundary; a synchronous CPU loop still occupies the single thread, blocking the event loop. Worker Threads provide real parallelism.

    Read the full bite: Offloading CPU-bound work with Worker Threads

  7. Question 7 of 30

    What is the primary consequence of running a long-running synchronous task in a Node.js application?

    Show the answer

    Answer: a · The application's event loop will become blocked, making the server unresponsive.

    The card states that a long-running synchronous computation will 'monopolize the single main thread, blocking the event loop entirely,' leading to an unresponsive application. Synchronous tasks are not automatically offloaded to background threads; they execute directly on the main thread, unlike asynchronous I/O operations.

    Read the full bite: The Node.js Event Loop: Concurrency on a Single Thread

  8. Question 8 of 30

    A Node.js API stops responding to every request whenever a user logs in, because the login handler calls crypto.pbkdf2Sync to verify a password. What is the most likely cause?

    Show the answer

    Answer: b · The synchronous call runs on the single main thread and blocks the event loop until it finishes

    pbkdf2Sync executes directly on the same thread that runs the event loop, so nothing else can be processed until it returns; the threadpool default is four, not zero, and the block has nothing to do with database connections.

    Read the full bite: Event Loop vs Crypto Module

  9. Question 9 of 30

    Why is it a problem to list a library your source code imports at runtime under devDependencies?

    Show the answer

    Answer: d · A production install that skips devDependencies leaves it missing, causing runtime errors

    Production installs omit devDependencies, so a runtime import placed there will be absent and throw module-not-found. Runtime libraries must live under dependencies.

    Read the full bite: dependencies vs devDependencies in package.json

  10. Question 10 of 30

    What does Node do first when it encounters require('fs')?

    Show the answer

    Answer: a · Matches it against built-in core modules, which take precedence

    Bare specifiers are checked against built-in core modules first; fs is compiled into the binary and resolves without touching node_modules. The package search only runs for non-core bare names.

    Read the full bite: Resolving core vs relative module specifiers

  11. Question 11 of 30

    What core problem does committing package-lock.json solve that package.json alone cannot?

    Show the answer

    Answer: c · It guarantees every install resolves to the exact same dependency tree, including transitive packages

    package.json uses version ranges, so installs can drift; the lockfile pins exact versions and tree shape for all transitive deps, making installs deterministic. It does not store tarballs or block additions.

    Read the full bite: Why package-lock.json must be committed

  12. Question 12 of 30

    Which statement accurately describes how process.nextTick() callbacks are prioritized within the Node.js event loop?

    Show the answer

    Answer: b · They execute immediately after the current JavaScript operation, before any timers or I/O.

    process.nextTick() callbacks are processed with the highest precedence, immediately after the current JavaScript operation completes and before the event loop proceeds to microtasks, timers, or I/O. Option D is incorrect because nextTick callbacks are processed *before* the microtask queue.

    Read the full bite: process.nextTick(): Cutting in Line on the Event Loop

  13. Question 13 of 30

    Which statement about using ES Modules instead of CommonJS in Node is accurate?

    Show the answer

    Answer: d · ESM lacks __dirname by default and is enabled via type module or .mjs

    ESM omits __dirname and require, and is enabled by type module or the .mjs extension. import is not an alias for require, and only ESM supports top-level await.

    Read the full bite: Choosing between CommonJS and ES Modules

  14. Question 14 of 30

    What is the fundamental problem Node.js streams are designed to solve for data handling?

    Show the answer

    Answer: a · Processing large datasets without exhausting system memory.

    The card states streams were created to 'process data piece by piece, keeping memory usage low and constant regardless of the total data size' because loading large files entirely into memory is inefficient or impossible. While streams can simplify I/O (option D), their core purpose is memory efficiency for large data, and they are not ideal for random access (option C).

    Read the full bite: Node.js Streams: Processing Data in Chunks, Not Blobs

  15. Question 15 of 30

    What is the primary advantage of using asynchronous child processes in Node.js?

    Show the answer

    Answer: d · To execute CPU-bound tasks without blocking the main event loop.

    The card explicitly states that child processes solve the problem of CPU-intensive operations blocking the single-threaded event loop by offloading heavy work. Option B describes the purpose of worker_threads, not child processes.

    Read the full bite: Node.js Child Processes: Escaping the Main Thread

  16. Question 16 of 30

    Why should the service layer in a layered Express API avoid referencing the request and response objects?

    Show the answer

    Answer: d · It keeps business logic framework-agnostic and unit-testable without HTTP

    Keeping req and res out of services makes the business logic reusable and testable without spinning up HTTP. Express does not forbid it and services are not on a separate thread.

    Read the full bite: Layered structure for a scalable Express API

  17. Question 17 of 30

    Given a dependency written as ^1.4.2, which upgrade would npm refuse to install on its own?

    Show the answer

    Answer: b · 2.0.0, a major release

    The caret allows updates below the next major, so anything under 2.0.0 is permitted, but 2.0.0 itself is excluded. The tilde would be the operator that also blocks 1.7.0.

    Read the full bite: SemVer and the caret vs tilde range operators

  18. Question 18 of 30

    How does Libuv ensure non-blocking I/O for operations that lack native asynchronous support from the operating system?

    Show the answer

    Answer: c · It uses a dedicated thread pool to execute these operations, preventing the main JavaScript thread from blocking.

    Libuv employs a thread pool for I/O operations that do not have native asynchronous OS APIs, allowing these tasks to run in the background without blocking the main JavaScript event loop. Relying on the main thread or just JavaScript Promises would not achieve true non-blocking I/O at the system level.

    Read the full bite: Libuv: The Engine Behind Node.js Async I/O

  19. Question 19 of 30

    When module B requires module A in the middle of A's own loading, what does B receive?

    Show the answer

    Answer: c · A's exports object as populated so far, possibly incomplete

    CommonJS caches the exports object at load start and returns it as-is, so B gets whatever A has assigned up to that point. It is not re-executed, does not throw, and the reference is not retroactively backfilled.

    Read the full bite: Circular dependencies in CommonJS modules

  20. Question 20 of 30

    Why can two installed major versions of the same library cause instanceof checks to fail across packages?

    Show the answer

    Answer: b · Each copy is a distinct module instance with its own classes, so cross-copy instanceof returns false

    Two physical copies are separate module instances with separate class identities, so an object from one copy is not an instance of the other copy's class. npm does not strip prototypes.

    Read the full bite: Diamond dependencies and nested node_modules

  21. Question 21 of 30

    Why does copying all source before npm install slow down rebuilds after a code change?

    Show the answer

    Answer: a · The COPY of changed source invalidates the install layer and everything after it

    Cache invalidation cascades from the first changed instruction, so copying edited source before install busts the install layer; npm install does respect the cache when its inputs are unchanged.

    Read the full bite: Optimize Dockerfile layer caching for npm install

  22. Question 22 of 30

    What is the primary advantage of employing the Node.js cluster module in a multi-core environment?

    Show the answer

    Answer: c · It allows a single Node.js application to utilize all available CPU cores for I/O-bound network operations on one machine.

    The cluster module's core purpose is to enable a single Node.js application to fully utilize all CPU cores on a *single* multi-core machine for I/O-bound tasks like network applications. It is not designed for direct memory sharing (that's worker_threads), distributing across multiple physical servers, or low-overhead IPC for frequent data exchange, as IPC overhead is noted as high.

    Read the full bite: Node.js Cluster: Scaling on a Single Machine

  23. Question 23 of 30

    What is a distinctive advantage of monorepo workspaces over consuming shared code as published private packages?

    Show the answer

    Answer: d · A breaking change and all consumer updates can land in one atomic commit without a publish step

    Workspaces link internal packages locally, so changes to shared code and its consumers ship in a single atomic commit. Published packages instead require a publish-and-bump cycle and risk version drift.

    Read the full bite: Monorepo workspaces vs private npm packages

  24. Question 24 of 30

    According to the CommonJS mental model, what is the default state of variables and functions defined within a module file?

    Show the answer

    Answer: b · They are private to the module unless explicitly exported.

    The card states, "By default, all tools and materials (variables, functions) inside are private. To share a tool, you place it on a public shelf called exports." This means they are private unless explicitly exported. Options A and B describe the opposite of CommonJS's encapsulation, and D is incorrect because variables are accessible within their own module before any import.

    Read the full bite: CommonJS: Node.js's Original Module System

  25. Question 25 of 30

    What is the primary function of the package.json file when a new developer sets up a Node.js project?

    Show the answer

    Answer: d · It lists all external code the project depends on and defines how to run common tasks.

    The correct answer is B because package.json explicitly lists all external libraries (dependencies) required for the project and defines runnable scripts. This allows a new developer to quickly install everything with 'npm install' and run tasks like 'npm start', making the project self-contained and reproducible. Option B is incorrect because while package.json can suggest a Node.js version, its primary role for initial setup is dependency and script management.

    Read the full bite: package.json: The Blueprint for Your Node.js Project

  26. Question 26 of 30

    Which statement about a Promise's state transitions is correct?

    Show the answer

    Answer: a · Once settled as fulfilled or rejected, the state is permanent and cannot change

    Settling is one-way and final; a Promise transitions from pending to exactly one of fulfilled or rejected and stays there. then callbacks run later as microtasks, not synchronously.

    Read the full bite: The three states of a JavaScript Promise

  27. Question 27 of 30

    What is a key architectural difference between adapter-static and adapter-node?

    Show the answer

    Answer: a · adapter-static pre-renders pages into HTML files at build time, whereas adapter-node produces a Node server for dynamic requests

    adapter-static outputs static HTML for CDN deployment while adapter-node creates a running Node server capable of SSR and API routes. A is tempting but wrong because Vite handles bundling; an adapter only repackages the already-bundled output for a specific platform.

    Read the full bite: What is a SvelteKit adapter and how do adapter-static and adapter-node differ?

  28. Question 28 of 30

    What is the main reason for differentiating between "dependencies" and "devDependencies" in a Node.js project?

    Show the answer

    Answer: c · To reduce the final production bundle size and enhance security.

    The card states this separation "prevents shipping unnecessary code to production, which saves disk space, reduces installation time, and minimizes the potential security attack surface." Option D is incorrect because the distinction aims to exclude development tools from production, not include them, to avoid bloat and security risks.

    Read the full bite: Dependencies vs. DevDependencies: What's the Difference?

  29. Question 29 of 30

    What is the primary mechanism that allows npm scripts to execute project-specific tools (like jest or webpack) without requiring them to be installed globally?

    Show the answer

    Answer: a · npm temporarily adds the project's node_modules/.bin directory to the system's PATH during script execution.

    The card states that npm temporarily adds the project's node_modules/.bin directory to the system's PATH, allowing local executables to be run by name. Option C is incorrect because npm does not automatically install global dependencies for scripts.

    Read the full bite: npm Scripts: Your Project's Command-Line Shortcuts

  30. Question 30 of 30

    When is Vite's low-level SSR API the most appropriate choice for a project?

    Show the answer

    Answer: b · When building a custom SSR framework or requiring unique server-side rendering control beyond existing plugins.

    The low-level SSR API is designed for advanced scenarios like framework development or highly custom server environments, offering full control. It is explicitly advised against for standard applications using popular frameworks, which should leverage higher-level SSR plugins.

    Read the full bite: Vite's Low-Level SSR API

Could you explain these out loud?

That is what an interview actually tests. Tezvyn gives you questions like these with what the interviewer is really checking, the answer that lands, and the mistake that ends the conversation, in the four minutes before your next meeting.

The iPhone app is on the way

We are building it. Until it lands, nothing here is held back from you: every interview card, your saved cards, streaks and the job board all work in Safari, plus hundreds of free practice quizzes of thirty questions each. Sign in and it all carries over to the app the day it arrives.

Want it as an icon? Tap Share at the bottom of Safari, then Add to Home Screen. It opens full screen and the cards you have read stay available offline.

Get it on Google PlayiPhone app coming soon