🌍 NodeJS · subject

NodeJS Core Concepts Syllabus

The Core Concepts syllabus for NodeJS in full: 3 chapters and 9 topics, every one listed below, plus 51 Core Concepts flashcards with answers.

3Chapters
9Topics
51Flashcards

Core Concepts syllabus: all 3 chapters

Expand any chapter to see its topics and sub-topics.

  1. Event-Driven Architecture

    3 topics
    • Event Loop
    • Event Emitters
    • Callbacks
  2. Non-Blocking I/O

    3 topics
    • Asynchronous Programming
    • Promises
    • Async/Await
  3. Modules and Packages

    3 topics
    • CommonJS Modules
    • ES6 Modules
    • npm (Node Package Manager)

NodeJS Core Concepts flashcards — 51 questions with answers

  1. In Node.js, what is the event loop?

    The event loop is the mechanism that lets Node.js perform non-blocking I/O by offloading operations to the system kernel/thread pool and processing their callbacks when they complete, despite JavaScript being single-threaded.

  2. List the six main phases of the Node.js event loop in order.

    1) timers, 2) pending callbacks, 3) idle/prepare (internal), 4) poll, 5) check, 6) close callbacks. It cycles through these repeatedly.

  3. Which event loop phase executes callbacks scheduled by setTimeout() and setInterval()?

    The timers phase.

  4. In which event loop phase are setImmediate() callbacks executed?

    The check phase (which runs immediately after the poll phase).

  5. What happens in the poll phase of the event loop?

    It retrieves new I/O events and executes their callbacks, and will block waiting for new I/O when appropriate (unless timers or setImmediate callbacks are pending).

  6. How does process.nextTick() relate to the event loop phases?

    process.nextTick() callbacks are not part of any phase; the nextTick queue is drained completely after the current operation finishes and before the event loop continues to the next phase (higher priority than Promise microtasks).

  7. What is the ordering priority between process.nextTick callbacks and Promise microtasks?

    After each operation, the process.nextTick queue is processed first, then the Promise microtask queue, before returning to the event loop phases.

  8. Why is Node.js described as single-threaded yet capable of high concurrency?

    JavaScript executes on a single main thread, but I/O is delegated to libuv's thread pool and the OS kernel, so many operations run concurrently in the background while the main thread stays free via non-blocking callbacks.

  9. What library provides the event loop and asynchronous I/O for Node.js?

    libuv, a C library that implements the event loop and a thread pool for asynchronous operations.

  10. In Node.js, what is the EventEmitter class and where does it come from?

    EventEmitter is a class from the built-in 'events' module that lets objects emit named events and register listener functions to handle them (the publish/subscribe pattern).

  11. Which two EventEmitter methods are used to register a listener and to trigger an event?

    on() (or addListener()) registers a listener; emit() synchronously triggers all listeners for a named event.

  12. What is the difference between EventEmitter's on() and once() methods?

    on() registers a listener that fires every time the event is emitted; once() registers a listener that fires only the first time and is then removed.

  13. How do EventEmitter listeners execute relative to emit()—synchronously or asynchronously?

    Listeners are called synchronously and in the order they were registered when emit() is invoked.

  14. What special event does EventEmitter emit when an error occurs, and what happens if it is unhandled?

    The 'error' event. If no listener is registered for it, EventEmitter throws the error and the Node.js process typically crashes.

  15. How do you remove EventEmitter listeners?

    Use removeListener()/off() to remove a specific listener, or removeAllListeners() to remove all listeners for an event.

  16. What is the default maximum number of listeners per event in EventEmitter, and what happens when exceeded?

    The default limit is 10; exceeding it logs a MaxListenersExceededWarning (a possible memory-leak warning), which you can change with setMaxListeners().

  17. In Node.js, what is a callback function?

    A callback is a function passed as an argument to another function, to be invoked later once an operation (often asynchronous) completes.

  18. What is the Node.js error-first callback convention?

    The callback's first argument is an error object (null if no error) and subsequent arguments carry successful result data, e.g. function(err, data){...}.

  19. What is 'callback hell' (the pyramid of doom)?

    Deeply nested callbacks resulting from sequential asynchronous operations, producing code that is hard to read, maintain, and handle errors in.

  20. Name three techniques to avoid or mitigate callback hell.

    Use named functions instead of anonymous nesting, modularize code, and use Promises or async/await instead of nested callbacks.

Show the other 31 Core Concepts flashcards
  1. What is the difference between synchronous and asynchronous code execution?

    Synchronous code runs sequentially, blocking until each operation completes; asynchronous code initiates an operation and continues without waiting, handling the result later via a callback, Promise, or await.

  2. What is blocking versus non-blocking in Node.js?

    Blocking operations halt further JavaScript execution until they finish (e.g., fs.readFileSync); non-blocking operations return immediately and deliver results later, keeping the event loop free.

  3. Why should CPU-bound work be avoided on the Node.js main thread?

    Long CPU-bound tasks block the single-threaded event loop, preventing it from processing other callbacks and making the application unresponsive; such work should be offloaded (e.g., worker threads).

  4. What is a Promise in JavaScript/Node.js?

    A Promise is an object representing the eventual completion (or failure) of an asynchronous operation and its resulting value, serving as a placeholder for a future result.

  5. What are the three states of a Promise?

    Pending (initial), fulfilled (resolved successfully), and rejected (failed). Once fulfilled or rejected it is 'settled' and immutable.

  6. Which methods handle a Promise's fulfillment and rejection?

    .then() handles fulfillment (and optionally rejection as a second argument), .catch() handles rejection, and .finally() runs regardless of outcome.

  7. What does Promise.all() do and how does it handle rejection?

    It takes an iterable of promises and returns a single promise that fulfills with an array of all results when all fulfill, but rejects immediately if any one promise rejects (fail-fast).

  8. How does Promise.allSettled() differ from Promise.all()?

    Promise.allSettled() waits for every promise to settle and never rejects; it returns an array of objects each with a status ('fulfilled' or 'rejected') and a value or reason.

  9. What does Promise.race() return?

    A promise that settles (fulfills or rejects) as soon as the first input promise settles, adopting that promise's value or reason.

  10. What does Promise.any() do?

    It fulfills as soon as any input promise fulfills; it rejects only if all promises reject, with an AggregateError containing all rejection reasons.

  11. What is promise chaining?

    Returning a value or new promise from a .then() handler so subsequent .then() calls process the resulting value in sequence, flattening asynchronous steps into a readable chain.

  12. In which queue are Promise resolution callbacks placed, and how does that affect timing?

    They are placed in the microtask queue, which is drained after the current operation and before the event loop moves to the next phase—so microtasks run before timers/setImmediate macrotasks.

  13. What is async/await in JavaScript?

    Syntactic sugar over Promises: the async keyword makes a function return a Promise, and await pauses execution inside that function until an awaited Promise settles, letting asynchronous code read like synchronous code.

  14. What does an async function always return?

    An async function always returns a Promise; returned values are wrapped in a resolved Promise, and thrown errors become a rejected Promise.

  15. How do you handle errors with async/await?

    Wrap awaited calls in a try/catch block; a rejected awaited Promise throws inside the try, which the catch handles.

  16. Where can the await keyword be used?

    Inside async functions, and at the top level of ES modules (top-level await); it cannot be used in ordinary synchronous functions.

  17. How can you run multiple asynchronous operations concurrently with async/await rather than sequentially?

    Start the operations without awaiting each immediately (or collect their promises) and await Promise.all() on them, instead of awaiting each one in turn, which would serialize them.

  18. What is CommonJS in Node.js?

    CommonJS is Node.js's original module system, which loads modules synchronously using require() to import and module.exports/exports to export.

  19. How do you export and import with CommonJS?

    Export by assigning to module.exports (or adding properties to exports); import with const x = require('./module').

  20. What is the difference between module.exports and exports in CommonJS?

    exports is initially a reference to module.exports; reassigning exports breaks that link, so to replace the whole export you must assign to module.exports directly. Only module.exports is actually returned by require().

  21. Is CommonJS module loading synchronous or asynchronous, and why does that matter?

    Synchronous—require() blocks until the module is loaded and evaluated. This suits server-side file access but is unsuitable for browsers where blocking network loads would harm performance.

  22. What are ES6 (ES) modules and which keywords do they use?

    The standardized ECMAScript module system using the import and export keywords for static, declarative module loading.

  23. How do you enable ES modules in a Node.js project?

    Use the .mjs file extension, or set "type": "module" in package.json so .js files are treated as ES modules.

  24. What is the difference between a default export and a named export in ES modules?

    A module can have one default export (export default ...) imported without braces under any name, and multiple named exports (export const foo) imported with braces by their exact names.

  25. Give three key differences between CommonJS and ES modules.

    1) Syntax: require/module.exports vs import/export. 2) Loading: CommonJS is synchronous/dynamic, ES modules are static and support asynchronous loading. 3) ES modules are strict mode by default and support top-level await, tree-shaking, and live bindings.

  26. What does 'static' analysis of ES module imports enable that CommonJS does not?

    Because import/export are resolved statically at parse time, tools can perform tree-shaking (dead-code elimination) and know the module graph before execution; CommonJS require() is dynamic and evaluated at runtime.

  27. What is npm?

    npm (Node Package Manager) is the default package manager for Node.js: a command-line tool and the world's largest registry for installing, sharing, and managing JavaScript packages and their dependencies.

  28. What is the purpose of the package.json file?

    It is the manifest for a Node.js project, defining metadata (name, version), scripts, and the project's dependencies and devDependencies.

  29. What is the difference between dependencies and devDependencies in package.json?

    dependencies are packages required at runtime in production; devDependencies are needed only during development and testing (e.g., test frameworks, linters) and are excluded with npm install --production.

  30. What does package-lock.json do?

    It records the exact resolved version and dependency tree of every installed package, ensuring reproducible, deterministic installs across environments.

  31. In semantic versioning MAJOR.MINOR.PATCH, what do the caret (^) and tilde (~) range specifiers mean?

    Given $MAJOR.MINOR.PATCH$: ^ allows updates that do not change the leftmost non-zero digit (typically MINOR and PATCH, e.g. ^1.2.3 permits <2.0.0), while ~ generally allows only PATCH-level updates (e.g. ~1.2.3 permits <1.3.0).

NodeJS Core Concepts FAQ

What is in the NodeJS Core Concepts syllabus?

NodeJS Core Concepts is split into 3 chapters: Event-Driven Architecture, Non-Blocking I/O and Modules and Packages. Together they contain 9 topics.

How many chapters are in NodeJS Core Concepts?

3 chapters, containing 9 topics. The largest chapter is Event-Driven Architecture, with 3 topics.

Are there flashcards for NodeJS Core Concepts?

Yes — a 51-card Core Concepts deck, printed in full in the flashcards section of this page and available in the Examius app with spaced repetition. The free plan covers one exam of your choice, including its flashcards; Examius Pro, a one-time purchase, unlocks every other exam and deck.