Last Sync: 2022-07-21 08:30:14

This commit is contained in:
tactonbishop 2022-07-21 08:30:14 +01:00
parent 95be1ee539
commit dc29317781
2 changed files with 6 additions and 4 deletions

View file

@ -6,15 +6,15 @@ tags:
- node-modules
---
# `events` module
In most case you won't interact with the `events` module directly since other modules and third-party modules are abstractions on top of this base-layer. For instance the `http` module is using events under the hood to handle requests and responses.
In most cases you won't interact with the `events` module directly since other modules and third-party modules are abstractions on top of it. For instance the `http` module is using events under the hood to handle requests and responses.
Another way of putting this is to say that all events in Node inherit from the `EventEmitter` constructor, which is the class you instantiate to create a new event. At bottom everything in Node is an event with a callback, created via event emitters.
Because Node's runtime is [event-driven](/Programming_Languages/NodeJS/Architecture/Event_loop.md), it is event-emitter cycles that are being processed by the Event Loop, although you may know them as `fs` or `http` (etc) events. The call stack that the Event Loop works through is just a series of event emissions and their associated callbacks.
## Event Emitters
* All objects that emit events are instances of the `EventEmitter` class. These objects expose an `eventEmitter.on()` function that allows one or more functions to be attached to named events emitted by the object.
* These functions are listeners of the emitter.
* All objects that emit events are instances of the `EventEmitter` class. This object exposes an `eventEmitter.on()` function that allows one or more functions to be attached to named events emitted by the object.
* These functions are **listeners** of the emitter.
## Basic syntax

View file

@ -6,11 +6,13 @@ tags:
- node-modules
---
# `fs` module
File System is an essential built-in module of Node that contains utility methods for working with files and directories.
Every method associated with `fs` has a *blocking* and *asynchronous* implementation. The former obviously blocks the [event queue](Event%20queue.md), the latter does not.
The asynchronous methods are useful to have in some contexts but in general and with real-world applications, you should be using the async implementation.
The synchronous methods are useful to have in some contexts but in general and with real-world applications, you should be using the async implementation so as to accord with the single-threaded event-driven architecture of Node.
## Methods