BACKEND30 questions • ~12 min
Node.js Fundamentals Quiz
Test your core Node.js backend concepts, event loop mechanics, and asynchronous architecture.
Node.js Fundamentals Quiz
Test your core Node.js backend concepts, event loop mechanics, and asynchronous architecture.
1. Node.js is described as 'single-threaded'. What does this primarily mean in the context of JavaScript execution?
- It can only handle one HTTP request at a time
- JavaScript code runs on a single call stack in one thread
- It uses only one CPU core for all operations
- It cannot run multiple Node.js processes on the same machine
2. What does `require('fs')` do in a Node.js module?
- Fetches the 'fs' package from the npm registry at runtime
- Loads and caches the built-in file system module, returning its exports object
- Creates a new file system instance for the current module only
- Registers a file system event listener on the process object
3. Which field in `package.json` specifies the entry point file that Node.js loads when your package is `require()`-d?
- start
- index
- main
- entry
4. What is the key difference between `fs.readFileSync()` and `fs.readFile()` in Node.js?
- `readFileSync` reads larger files; `readFile` is limited to 1 MB
- `readFileSync` blocks the event loop until the file is read; `readFile` is non-blocking and uses a callback
- `readFile` is deprecated; `readFileSync` is the modern API
- They are identical: the 'Sync' suffix is cosmetic
5. In Node.js, what is a callback?
- A built-in error type for async failures
- A function passed as an argument to another function, invoked when an async operation completes
- A synchronous wrapper around a Promise
- A special method on the EventEmitter class
6. How do you read an environment variable named `PORT` in a Node.js process?
- `env.get('PORT')`
- `process.env.PORT`
- `os.env('PORT')`
- `global.PORT`
7. Which built-in Node.js module would you use to join two path segments in a cross-platform safe way?
- `fs`
- `url`
- `path`
- `os`
8. What does `npm run build` execute?
- Downloads and installs all packages listed in `dependencies`
- Runs the `build` script defined under the `scripts` key in `package.json`
- Compiles all `.ts` files to `.js` using Node's built-in compiler
- Creates a production bundle and uploads it to npm
9. In a Node.js stack trace, what does the line `at Object.<anonymous> (app.js:42:15)` tell you?
- An anonymous object was exported from `app.js`
- The error originated at line 42, column 15 of `app.js`
- The file `app.js` has 42 exports
- Process memory usage at the time of the error
10. Which of the following is available in a browser's JavaScript runtime but NOT in Node.js by default?
- `setTimeout`
- `Promise`
- `window`
- `Array.prototype.map`
11. What is the correct order of execution for the following code? ```js setTimeout(() => console.log('A'), 0); setImmediate(() => console.log('B')); process.nextTick(() => console.log('C')); console.log('D'); ```
- D → A → B → C
- D → C → A → B
- D → C → B → A
- A → B → C → D
12. In what phase of the Node.js event loop does `setImmediate()` fire?
- Timers phase
- Poll phase
- Check phase
- Close callbacks phase
13. Which of the following has the highest execution priority in Node.js's async scheduling?
- `setTimeout(fn, 0)`
- `setImmediate(fn)`
- `process.nextTick(fn)`
- Resolved `Promise` `.then()` callbacks
14. What type of Node.js stream would you use to both read from and write to, AND transform the data in transit (e.g., a gzip compressor)?
- Readable stream
- Writable stream
- Duplex stream
- Transform stream
15. What is the primary purpose of the Node.js `cluster` module?
- To distribute npm packages across multiple machines
- To fork multiple worker processes that share the same server port, utilizing multiple CPU cores
- To spawn child processes that run independent scripts with no shared state
- To create thread pools for CPU-intensive synchronous tasks
16. How does `worker_threads` differ from `child_process` in Node.js?
- `worker_threads` share memory via `SharedArrayBuffer`; `child_process` spawns fully isolated OS processes
- `child_process` is faster for CPU tasks because it uses native threads
- `worker_threads` cannot communicate with the main thread
- They are interchangeable; the names are aliases
17. In V8's heap layout, what is the 'New Space' (Young Generation) used for?
- Storing compiled machine code for JIT-compiled functions
- Short-lived objects that are expected to be collected quickly
- Large objects over 1 MB that cannot fit in regular pages
- The call stack and local variable frames
18. When a Node.js module is `require()`-d a second time, what happens?
- The module file is re-read from disk and re-executed
- An error is thrown to prevent duplicate initialization
- The cached `exports` object from the first load is returned immediately
- A new isolated module instance is created
19. Which `EventEmitter` method registers a listener that fires only once and then automatically removes itself?
- `emitter.on(event, listener)`
- `emitter.once(event, listener)`
- `emitter.addOnceListener(event, listener)`
- `emitter.emit(event, { once: true })`
20. What is libuv's role in Node.js?
- It is the JavaScript engine that compiles and executes JS code
- It provides the cross-platform async I/O event loop, thread pool, and OS abstraction layer
- It manages npm package downloads and caching
- It implements the HTTP/2 protocol for Node's `http2` module
21. Which garbage collection algorithm does V8 use for the Young Generation (New Space)?
- Mark-Sweep
- Mark-Compact
- Scavenge (Cheney's semi-space copying)
- Reference counting
22. Why can a full Mark-Compact GC cycle cause observable latency spikes in a Node.js server?
- It temporarily doubles memory usage by copying the entire heap
- It runs stop-the-world pauses while compacting the Old Space, blocking the event loop
- It recompiles all JIT-optimized functions to free code cache memory
- It flushes the libuv thread pool and restarts all pending I/O operations
23. You run `node --prof app.js` and then `node --prof-process isolate-*.log`. What kind of output does this produce?
- A heap snapshot in JSON format compatible with Chrome DevTools
- A human-readable statistical CPU profile showing hot functions and their call percentages
- A timeline of all GC pauses with their durations in milliseconds
- A network waterfall diagram of all HTTP requests made during the run
24. Which of the following patterns is the most common cause of memory leaks in long-running Node.js servers?
- Using `const` instead of `let` for module-level variables
- Accumulating listeners on an EventEmitter without ever calling `removeListener`
- Calling `JSON.parse` on large strings repeatedly
- Using `async/await` instead of raw callbacks
25. What does the Node.js flag `--max-old-space-size=4096` control?
- The maximum number of files that can be open simultaneously
- The size of libuv's thread pool in megabytes
- The upper limit of V8's Old Space heap in megabytes before OOM is thrown
- The maximum allowed size of a single JSON payload parsed with `JSON.parse`
26. A synchronous CPU-bound loop running for 2 seconds is accidentally placed in an HTTP request handler. What is the most accurate description of the impact?
- Only that specific request is delayed; other requests continue normally
- The event loop poll phase is blocked for 2 seconds, stalling ALL other incoming requests and timers
- Node automatically offloads the loop to libuv's thread pool to prevent blocking
- The cluster master process detects the block and restarts the worker
27. What is back-pressure in Node.js streams, and what role does `highWaterMark` play?
- Back-pressure is an HTTP rate-limit; `highWaterMark` sets the requests-per-second ceiling
- Back-pressure is the signal that a writable stream's buffer is full; `highWaterMark` sets the buffer size threshold at which `write()` returns `false`
- Back-pressure is a V8 GC pause; `highWaterMark` triggers early GC when heap exceeds this fraction
- Back-pressure is unused in Node.js streams; it is only relevant to TCP sockets
28. What is the primary advantage of N-API (now Node-API) over previous native addon interfaces?
- It allows writing native addons in Python instead of C/C++
- It provides an ABI-stable interface so native addons do not need to be recompiled for every new Node.js version
- It gives native addons direct access to V8's garbage collector to manage their own memory
- It automatically parallelizes native addon execution across all CPU cores
29. How do V8 'hidden classes' (also called 'shapes' or 'maps') improve JavaScript object performance?
- They compress object keys using a dictionary to reduce memory per object
- They allow V8 to generate optimized machine code by tracking object property layouts and reusing them across instances with the same shape
- They hide private class fields from the garbage collector to prevent premature collection
- They pre-allocate a fixed heap page per constructor function
30. When using PM2 to achieve zero-downtime restarts (`pm2 reload`), what mechanism does PM2 use?
- It pauses the load balancer, restarts all workers simultaneously, then resumes traffic
- It creates a new worker, waits for it to signal readiness, routes traffic to it, then gracefully kills the old worker: one at a time
- It patches the running process in memory without spawning a new one
- It relies on the OS kernel's live-patching feature to swap code pages atomically
About this quiz
This interactive quiz is crafted to provide a quick, engaging, and dynamic experience. Questions feature randomized options and your final result is computed immediately upon completion. Retake anytime and share your score with friends!
Quiz highlights:
- ✓100% free with no sign-up required
- ✓Engaging questions with instant feedback
- ✓Download custom story card and share with friends
Frequently Asked Questions
As you answer each question, the engine calculates your traits and choices to generate your unique result instantly.