[{"id":"nodejsbeginner-001","courseId":"nodejs-beginner","domain":"event-loop-async","topic":"Blocking versus non-blocking calls","prompt":"A request handler calls fs.readFileSync('/file.md') for every request. While one of those reads is in progress, what happens to other JavaScript in the process?","hint":"Notice the Sync suffix on the method name.","explain":"Some Node.js calls hold the JavaScript thread until their work ends; others return at once and report later through a callback. The kind of call decides whether other code can run meanwhile.","source":"https://nodejs.org/en/learn/asynchronous-work/overview-of-blocking-vs-non-blocking","interaction":{"type":"single"},"options":[{"id":"a","text":"Only that handler waits; other callbacks keep running normally.","whyNot":"Blocking stops the event loop itself, so every other piece of JavaScript waits too, not just this handler."},{"id":"b","text":"The read runs on a second JavaScript thread, so nothing waits.","whyNot":"JavaScript is single-threaded and cannot create new threads to run in parallel, so the read does not run beside it."},{"id":"c","text":"Nothing else runs JavaScript in the process until the read finishes.","why":"A synchronous call blocks: the event loop can't run JavaScript while the blocking operation is still occurring."},{"id":"d","text":"The call returns a promise at once, so the data is not ready yet.","whyNot":"readFileSync returns the data itself. The callback version, readFile, returns right away and delivers the data to a callback."}],"answer":"c","explanation":"Synchronous (Sync-suffixed) I/O methods block the event loop until the operation completes; asynchronous versions return immediately and call a callback later.","concept":"Synchronous (Sync-suffixed) I/O methods block the event loop until the operation completes; asynchronous versions return immediately and call a callback later.","rev":1,"updatedAt":"2026-10-23","kind":"scenario","code":"const data = fs.readFileSync('/file.md');\nconsole.log(data);","takeaways":["A Sync method blocks the event loop until the I/O finishes.","Use the callback or promise version of I/O in request handlers."]},{"id":"nodejsbeginner-002","courseId":"nodejs-beginner","domain":"event-loop-async","topic":"Error-first callbacks","prompt":"You call fs.readFile('/file.json', callback). If reading fails, which argument of the callback reports the error?","hint":"Look at the convention Node.js uses for every callback's parameters.","explain":"Node.js callbacks follow a convention about their parameters. Knowing which parameter is reserved for failure tells you what to check before you touch the result.","source":"https://nodejs.org/en/learn/asynchronous-work/javascript-asynchronous-programming-and-callbacks","interaction":{"type":"single"},"options":[{"id":"a","text":"The first argument, named err.","why":"Error-first callbacks put the error object in the first parameter, and it is null when nothing went wrong."},{"id":"b","text":"The second argument, which is null when reading fails.","whyNot":"Errors go in the first parameter. The second parameter holds the data when the read succeeds."},{"id":"c","text":"The last argument, after the data.","whyNot":"Node.js callbacks don't add an error at the end; the error comes first, before any data."},{"id":"d","text":"Nothing reaches the callback; the failure is thrown from the readFile call.","whyNot":"The async form reports failure through the callback, and the author decides whether to throw; the call itself doesn't throw."}],"answer":"a","explanation":"Node.js callbacks are error-first: the first parameter is the error object (null when there is no error), and later parameters carry results.","concept":"Node.js callbacks are error-first: the first parameter is the error object (null when there is no error), and later parameters carry results.","rev":1,"updatedAt":"2026-10-23","kind":"scenario","code":"fs.readFile('/file.json', (err, data) => {\n  if (err) return console.log(err);\n  console.log(data);\n});","takeaways":["In Node.js callbacks, check the first argument before using the data.","Async errors arrive in the callback, not as a throw at the call site."]},{"id":"nodejsbeginner-003","courseId":"nodejs-beginner","domain":"event-loop-async","topic":"Promise then and catch handlers","prompt":"In promise.then(onOk).catch(onErr), if onOk throws an error, onErr is called with that error.","hint":"Follow the rejection from the failing step down the chain.","explain":"Each .then() returns a new promise, which links the steps together. A settled result moves along that link until a handler deals with it.","source":"https://nodejs.org/en/learn/asynchronous-work/discover-promises-in-nodejs","interaction":{"type":"true-false"},"options":[{"id":"a","text":"True","why":".catch() handles rejections from anywhere earlier in the chain, including a throw inside an onOk callback."},{"id":"b","text":"False","whyNot":"An error inside onOk becomes a rejection that passes down the chain to the next .catch()."}],"answer":"a","explanation":".catch() handles any rejection from the promise chain before it, including errors thrown inside .then() callbacks.","concept":".catch() handles any rejection from the promise chain before it, including errors thrown inside .then() callbacks.","rev":1,"updatedAt":"2026-10-23","kind":"scenario","code":"promise\n  .then(onOk)\n  .catch(onErr);","takeaways":["One .catch() at the end of a chain can handle errors from every step before it."]},{"id":"nodejsbeginner-004","courseId":"nodejs-beginner","domain":"event-loop-async","topic":"async and await syntax","prompt":"A teammate asks how async and await behave in a Node.js service. Which TWO statements are correct?","hint":"Think about what each keyword does on its own inside a function.","explain":"async and await let promise-based code read step by step. Each keyword changes how a function returns or pauses, so consider what a function marked async hands back.","source":"https://nodejs.org/en/learn/asynchronous-work/discover-promises-in-nodejs","interaction":{"type":"multiple","tellCount":true},"options":[{"id":"a","text":"In a CommonJS file you can write await at the top level without wrapping it in a function.","whyNot":"Top-level await is available in ECMAScript modules; it isn't how CommonJS files work."},{"id":"b","text":"An async function always returns a Promise, even when it returns a plain value.","why":"async makes a function return a Promise, so callers can chain .then() or await it."},{"id":"c","text":"async moves the function body onto a separate thread that runs in parallel with other code.","whyNot":"JavaScript is single-threaded and code can't create new threads; async doesn't make parallel threads."},{"id":"d","text":"A try/catch around an await cannot catch a rejected promise, because await never throws.","whyNot":"A rejected promise makes await throw, so a surrounding try/catch does catch it."},{"id":"e","text":"await pauses that async function until the Promise settles, then gives you its result.","why":"Execution resumes after the await once the Promise settles, and the await expression gives its value."},{"id":"f","text":"A function marked async runs faster than a normal function, because its body is compiled for parallel work.","whyNot":"async changes the return type to a Promise; it adds no speed and no parallel execution."}],"answer":"be","explanation":"An async function always returns a Promise, and await pauses the surrounding async function until the awaited Promise settles.","concept":"An async function always returns a Promise, and await pauses the surrounding async function until the awaited Promise settles.","rev":1,"updatedAt":"2026-10-23","kind":"scenario","takeaways":["An async function always returns a Promise.","await pauses only the surrounding async function until its Promise settles."]},{"id":"nodejsbeginner-005","courseId":"nodejs-beginner","domain":"event-loop-async","topic":"setTimeout delay precision","prompt":"Code calls setTimeout(fn, 100), then runs a synchronous loop for two seconds. The statement: fn still runs at the 100 ms mark, while the loop is busy.","hint":"Ask whether the loop can run a timer callback while JavaScript is still running.","explain":"Timer callbacks are run by the event loop, so their timing depends on when the loop gets back to them. Consider what a long synchronous task does to the loop.","source":"https://nodejs.org/api/timers.html#settimeoutcallback-delay-args","interaction":{"type":"true-false"},"options":[{"id":"a","text":"True","whyNot":"Node.js can't interrupt running JavaScript to fire a timer, so fn waits until the loop is free."},{"id":"b","text":"False","why":"The loop can't run fn while the synchronous work holds the thread, so fn runs late, after its delay has passed."}],"answer":"b","explanation":"Timer callbacks run only when the event loop gets back to them, so a long synchronous task can make a timer fire later than its delay.","concept":"Timer callbacks run only when the event loop gets back to them, so a long synchronous task can make a timer fire later than its delay.","rev":1,"updatedAt":"2026-10-23","kind":"scenario","takeaways":["A timer's delay is not exact; a busy event loop fires it late.","Keep synchronous work short so timers and I/O callbacks run on time."]}]