Node JS Design Patterns Flashcards
(42 cards)
What is the core principle of the Node.js core?
Having the smallest possible set of functionalities, leaving the rest to userland modules
This principle allows the community to experiment and iterate quickly on solutions.
What is the main building block for creating applications in Node.js?
Modules
Modules structure the code of a program and facilitate reusable libraries.
Name two precepts from the Unix philosophy that Node.js embodies.
- Small is beautiful
- Make each program do one thing well
What problem does Node.js’s module manager solve?
Dependency hell
It allows multiple packages to depend on different versions of the same package without conflicts.
List three advantages of small modules in Node.js.
- Easier to understand and use
- Simpler to test and maintain
- Small in size and perfect for use in the browser
What does the Don’t Repeat Yourself (DRY) principle advocate?
Sharing or reusing even the smallest piece of code
What is the desired characteristic of Node.js modules in terms of API exposure?
Exposing a minimal set of functionalities
True or False: Node.js modules are often designed to be extended.
False
They are created to be used rather than extended.
What does the KISS principle stand for?
Keep It Simple, Stupid
Who coined the term ‘worse is better’?
Richard P. Gabriel
What is the main disadvantage of traditional blocking I/O?
It blocks the execution of the thread until the operation completes.
What is the typical solution for handling multiple connections in traditional blocking I/O?
Using a separate thread (or process) for each concurrent connection
What does non-blocking I/O allow?
The system call returns immediately without waiting for the data
Fill in the blank: In non-blocking I/O, if no data is available, the function returns _______.
a predefined constant indicating no data
What is busy-waiting in the context of non-blocking I/O?
Actively polling the resource within a loop until data is available
What is event demultiplexing?
A mechanism to handle concurrent non-blocking resources efficiently
How does the synchronous event demultiplexer work?
Watches multiple resources and returns events when operations complete
What is the event loop in Node.js?
The process that blocks until new events are available to process
What does the reactor pattern in Node.js associate with each I/O operation?
A handler, represented by a callback function
What is one of the benefits of using a single-threaded model in Node.js?
Minimizing total idle time of the thread
True or False: The absence of in-process race conditions allows for simpler concurrency strategies in Node.js.
True
What is the reactor pattern?
A specialization of algorithms that associates a handler with each I/O operation.
In Node.js, what is a handler represented by?
A callback (or cb for short) function.
What does the Event Demultiplexer do in the reactor pattern?
It receives new I/O operation requests and returns control immediately.