Node JS Design Patterns Flashcards

(42 cards)

1
Q

What is the core principle of the Node.js core?

A

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.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
2
Q

What is the main building block for creating applications in Node.js?

A

Modules

Modules structure the code of a program and facilitate reusable libraries.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
3
Q

Name two precepts from the Unix philosophy that Node.js embodies.

A
  • Small is beautiful
  • Make each program do one thing well
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
4
Q

What problem does Node.js’s module manager solve?

A

Dependency hell

It allows multiple packages to depend on different versions of the same package without conflicts.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
5
Q

List three advantages of small modules in Node.js.

A
  • Easier to understand and use
  • Simpler to test and maintain
  • Small in size and perfect for use in the browser
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
6
Q

What does the Don’t Repeat Yourself (DRY) principle advocate?

A

Sharing or reusing even the smallest piece of code

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
7
Q

What is the desired characteristic of Node.js modules in terms of API exposure?

A

Exposing a minimal set of functionalities

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
8
Q

True or False: Node.js modules are often designed to be extended.

A

False

They are created to be used rather than extended.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
9
Q

What does the KISS principle stand for?

A

Keep It Simple, Stupid

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
10
Q

Who coined the term ‘worse is better’?

A

Richard P. Gabriel

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
11
Q

What is the main disadvantage of traditional blocking I/O?

A

It blocks the execution of the thread until the operation completes.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
12
Q

What is the typical solution for handling multiple connections in traditional blocking I/O?

A

Using a separate thread (or process) for each concurrent connection

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
13
Q

What does non-blocking I/O allow?

A

The system call returns immediately without waiting for the data

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
14
Q

Fill in the blank: In non-blocking I/O, if no data is available, the function returns _______.

A

a predefined constant indicating no data

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
15
Q

What is busy-waiting in the context of non-blocking I/O?

A

Actively polling the resource within a loop until data is available

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
16
Q

What is event demultiplexing?

A

A mechanism to handle concurrent non-blocking resources efficiently

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
17
Q

How does the synchronous event demultiplexer work?

A

Watches multiple resources and returns events when operations complete

18
Q

What is the event loop in Node.js?

A

The process that blocks until new events are available to process

19
Q

What does the reactor pattern in Node.js associate with each I/O operation?

A

A handler, represented by a callback function

20
Q

What is one of the benefits of using a single-threaded model in Node.js?

A

Minimizing total idle time of the thread

21
Q

True or False: The absence of in-process race conditions allows for simpler concurrency strategies in Node.js.

22
Q

What is the reactor pattern?

A

A specialization of algorithms that associates a handler with each I/O operation.

23
Q

In Node.js, what is a handler represented by?

A

A callback (or cb for short) function.

24
Q

What does the Event Demultiplexer do in the reactor pattern?

A

It receives new I/O operation requests and returns control immediately.

25
What happens when a set of I/O operations completes?
The Event Demultiplexer pushes corresponding events into the Event Queue.
26
What does the Event Loop do in the reactor pattern?
It iterates over the Event Queue and invokes the associated handlers.
27
How does a Node.js application exit?
When there are no more pending operations in the event demultiplexer and no more events in the event queue.
28
What is libuv?
The low-level I/O engine of Node.js that abstracts system calls and implements the reactor pattern.
29
Which operating systems use different interfaces for the event demultiplexer?
Linux (epoll), macOS (kqueue), Windows (I/O completion port API).
30
What three components are needed to build the full Node.js platform?
* Bindings for libuv and low-level functionalities * V8 JavaScript engine * Core JavaScript library implementing Node.js API.
31
What is a significant difference between JavaScript in Node.js and in browsers?
Node.js does not have a DOM or window/document objects but has access to OS services.
32
What allows Node.js applications to run the latest JavaScript features?
The use of recent V8 versions and the ability to target specific Node.js versions.
33
What is CommonJS?
The original Node.js module system using the require keyword to import modules.
34
What is the ES modules syntax in Node.js?
The modern module syntax that uses the import keyword, but with different implementation details.
35
What can you access with the fs module in Node.js?
Any file on the filesystem, subject to OS-level permissions.
36
What powerful capability does Node.js offer regarding native code?
The ability to create userland modules that bind to native code.
37
What is the advantage of using the N-API interface in Node.js?
It allows for reusing existing or new components written in C/C++.
38
What is WebAssembly (Wasm)?
A low-level instruction format that allows compiling languages like C++ or Rust into a format understandable by JavaScript VMs.
39
What is the essence of 'Node way' in programming?
Writing smaller, simpler modules that expose only the necessary functionality.
40
What are the three pillars of Node.js architecture?
* V8 * libuv * Core JavaScript library.
41
True or False: Node.js applications are limited to browser features.
False.
42
Fill in the blank: The reactor pattern handles I/O by blocking until new events are available from a set of observed _______.
[resources]