Log In
Join
for free
Back To Course Home
Node.js Design Patterns
0% completed
Overview
Introduction to the Course
The Node.js Platform
Introduction
The Node.js Philosophy
How Node.js Works
JavaScript in Node.js
Summary
Quiz
The Module System
Introduction
CommonJS Modules
The Resolving Algorithm
Module Definition Patterns (I)
Module Definition Patterns (II)
ESM: ECMAScript Modules
ESM: Named Exports and Imports
ESM: Default, Mixed, and Async
Module Loading in Depth
Modifying Other Modules
ESM and CommonJS Differences and Interoperability
Summary
Quiz
Callbacks and Events
Introduction
The Callback Pattern: Continuation-Passing Style (CPS)
The Callback Pattern: Synchronous vs. Asynchronous (I)
The Callback Pattern: Synchronous vs. Asynchronous (II)
The Callback Pattern: Node.js Conventions
The Observer Pattern: The EventEmitter Class
The Observer Pattern: Observable Objects
The Observer Pattern: Synchronous and Asynchronous Events
EventEmitter vs. Callbacks
Summary
Exercise: A Simple Event
Exercise: Ticker
Exercise: A Simple Modification
Exercise: Playing with Errors
Asynchronous Control Flow Patterns with Callbacks
Introduction
Difficulties of Asynchronous Programming: Web Spider
Callback Best Practices: Callback Discipline
Sequential Execution: Web Spider Version 2
Sequential Execution: Crawling of Links
Sequential Execution: The Pattern
Parallel Execution: Web Spider Version 3
Parallel Execution: The Pattern
Limited Parallel Execution
Globally Limiting Concurrency
Web Spider Version 4
The Async Library
Summary
Exercise: File Concatenation
Exercise: List Files Recursively
Exercise: Recursive Find
Asynchronous Control Flow Patterns with Promises and Async/Await
Introduction
Promises
Sequential Execution and Iteration
Parallel Execution
Limited Parallel Execution and the TaskQueue class
Updating the Web Spider
Async/Await Pair in Asynchronous Code
Error Handling with async/await
Sequential Execution and Iteration with Async/Await
Parallel Execution Using Async/Await and Promise.all()
Limited Parallel Execution
The Problem with Infinite Recursive Promise Resolution Chains
Summary
Exercise: Dissecting Promise.all()
Exercise: TaskQueue with Promises
Exercise: Producer-Consumer with Promises
Exercise: An Asynchronous map()
Coding with Streams
Introduction
Spatial Efficiency
Time Efficiency
Composability
Getting Started with Streams
Readable Streams: Non-Flowing and Flowing Modes
Implementing Readable Streams
Readable Streams: Simplified Construction and Iterables
Writable Streams: Writing a Stream and Backpressure
Writable Streams: Implementation
Duplex Streams
Implementing Transform Streams
Filtering and Aggregating Data with Transform Streams
PassThrough Streams
Lazy Streams
Pipes and Error Handling
Better Error Handling with pipeline()
Asynchronous Control Flow Patterns with Streams
Unordered Parallel Execution
Unordered Limited Parallel Execution
Asynchronous Control Flow Patterns: Ordered Parallel Execution
Piping Patterns: Combining Streams
Piping Patterns: Forking Streams
Merging Streams: Merging Text Files
Piping Patterns: Multiplexing and Demultiplexing
Piping Patterns: Multiplexing and Demultiplexing Object Streams
Summary
Exercise: Data Compression Efficiency
Exercise: Stream Data Processing
Creational Design Patterns
Introduction
Factory Pattern: Decoupling Object Creation
Factory Pattern: Encapsulation and Simple Code Profiler
Builder Pattern
Builder Pattern: Implementing a URL Object Builder
Revealing Constructor
Singleton Pattern
Wiring Modules: Singleton Dependencies
Wiring Modules: Dependency Injection
Summary
Exercise: Console Color Factory
Exercise: Request Builder
Exercise: A Tamper-Free Queue
Structural Design Patterns
Introduction
Proxy Pattern: Techniques for Implementing Proxies (I)
Proxy Pattern: Techniques for Implementing Proxies (II)
Proxy Pattern: Creating a Logging Writable Stream
Proxy Pattern: Change Observer pattern with Proxy
Decorator Pattern
Decorating a LevelUP database
The Line between the Proxy and Decorator Pattern
The Adapter Pattern
Summary
Exercise: HTTP Client Cache
Exercise: Timestamped Logs
Exercise: Colored Console Output
Exercise: A Virtual Filesystem
Exercise: The Lazy Buffer
Behavioral Design Patterns
Introduction
Strategy Pattern
State Pattern
Implementing a Basic Failsafe Socket
Template Pattern
Iterator Pattern
The Iterable Protocol
Iterator Built-Ins
Generators Pattern
Async Iterators
Async Generators
Middleware Pattern
Creating a Middleware Framework for ZeroMQ
Implementing the Middleware to Process Messages
Command Pattern
Implementation of Command Pattern
Summary
Exercise: Logging with Strategy
Exercise: Logging with Template
Exercise: Warehouse Item
Exercise: Logging with Middleware
Universal JavaScript for Web Applications
Introduction
Sharing Code with the Browser
Module Bundlers
Using Webpack
Fundamentals of Cross-Platform Development (I)
Fundamentals of Cross-Platform Development (II)
Fundamentals of Cross-Platform Development (III)
A Brief Introduction to React
Alternatives to the react.createElement() Method
Stateful Components
Creating a Universal JavaScript App
Server-Side Rendering
Asynchronous Data Retrieval
Universal Data Retrieval
Implementing Async Pages
Summary
Quiz
Advanced Recipes
Introduction
Dealing with Asynchronously Initialized Components
Pre-Initialization Queues
Asynchronous Request Batching and Caching
An API Server without Caching or Batching
Batching and Caching with Promises
Canceling Asynchronous Operations
Cancelable Async Functions with Generators
Running CPU-Bound Tasks
Interleaving with the setImmediate Function
Using External Processes (I)
Using External Processes (II)
Using Worker Threads
Summary
Exercise: Proxy with Pre-Initialization Queues
Exercise: Batching and Caching with Callback
Exercise: Deep Async Cancelable
Scalability and Architectural Patterns
Introduction
An Introduction to Application Scaling
Cloning and Load Balancing
Building a Simple HTTP Server
Zero-Downtime Restart
Dealing with Stateful Communications
Scaling with a Reverse Proxy
Dynamic Horizontal Scaling
Peer-to-Peer Load Balancing
Scaling Applications Using Containers (I)
Scaling Applications Using Containers (II)
Decomposing Complex Applications
Integration Patterns in a Microservice Architecture
Summary
Quiz
Messaging and Integration Patterns
Introduction
Fundamentals of a Messaging System
Publish/Subscribe Pattern
Publish/Subscribe Pattern Using Redis
Peer-To-Peer Publish/Subscribe with ZeroMQ
Reliable Message Delivery with Queues
Reliable Messaging with Streams
Task Distribution Patterns
Task Distribution Tasks with ZeroMQ
Pipelines and Competing Consumers in AMQP
Distributing Tasks with Redis Streams
Request/Reply Patterns
Return Address
Summary
Quiz
Conclusion
Wrap Up
Summary
Get a recap of what we learned in this chapter.
Press
+
to interact
Get hands-on with 1400+ tech skills courses.
Start Free Trial