FlashKeepers

Web Development · College · College and University

Node.js I: Core Modules and the Event Loop

Node.js event loop phases, modules, fs, path, streams, buffers, process, events and npm basics.

About this set

40 basic cards for College Web Development. Set 1 of 2 in Node.js. It opens with "What is the Node.js event loop?" and "Name the six main phases of the Node.js event loop". Study it alongside the other College sets below.

40 cards · basic cards · AI-written, checked twice. Edit anything.

Study this set free Look inside first Get FlashKeepers for iPhone

Opens in your browser, no account. Get the iPhone and iPad app · Android app

What is the Node.js event loop?
Show answerThe mechanism that allows Node.js to perform non-blocking I/O operations by delegating work to the system kernel and executing callbacks when operations complete.
Name the six main phases of the Node.js event loop.
Show answertimers, pending callbacks, idle/prepare, poll, check, close callbacks
What happens in the timers phase of the event loop?
Show answerCallbacks scheduled by setTimeout() and setInterval() are executed if their delay has expired.
What happens in the pending callbacks phase of the event loop?
Show answerCallbacks deferred to the next iteration of the event loop are executed, typically for I/O operations that failed.
What happens in the idle/prepare phase of the event loop?
Show answerInternal preparation occurs for the next phases; this phase is rarely encountered in user code.
What happens in the poll phase of the event loop?
Show answerThe event loop retrieves new I/O events and executes their associated callbacks; it handles file system, network, and other async operations.
What happens in the check phase of the event loop?
Show answerCallbacks scheduled by setImmediate() are executed.
What happens in the close callbacks phase of the event loop?
Show answerCallbacks for closed connections and aborted operations are executed.
What is a Node.js module?
Show answerA reusable block of code whose existence does not accidentally impact other code; a file containing JavaScript functionality that can be used in other files.
What does require() do?
Show answerIt loads a module and returns the module's exports so it can be used in the current file.
What is module.exports?
Show answerAn object that defines what a module exports and makes it available to other modules that require() it.
What is the difference between CommonJS and ES modules in Node.js?
Show answerCommonJS uses require() and module.exports; ES modules use import and export statements. Node.js uses CommonJS by default unless .mjs extension or type field is specified.
How do you export a function from a module?
Show answerAssign the function to module.exports, for example: module.exports = function() { ... };
What does fs.readFile() do?
Show answerReads the contents of a file asynchronously without blocking; requires a callback that receives the file data.
What does fs.readFileSync() do?
Show answerReads the contents of a file synchronously and blocks execution until the read completes; returns the file data directly.

25 more cards in the app

Study this set free