Preface vii
1. Node Fundamentals....1
Introducing Node....1
The JavaScript Language....3
Executing Node Code....4
Using Built-In Modules....7
Using Packages....10
ES Modules....15
Asynchronous Operations....19
The Non-Blocking Model....21
Node Built-In Modules....28
Node Packages....30
Arguments Against Node....31
Summary....32
2. Scripts and Modules....35
Node CLI....35
Options and Arguments....36
Environment Variables....40
REPL Mode....43
Node Modules....49
Resolving Modules....49
Loading Modules....50
Scoping Modules....51
Executing Modules....53
Caching Modules....57
Summary....58
3. Asynchrony and Events....59
Sync Versus Async Handling....59
Handler Functions....63
Promises....65
async/await....67
An Analogy for Promises....69
The Event Loop....72
Event Emitters....74
Asynchrony....76
Errors....78
Examples....79
Summary....81
4. Errors and Debugging....83
Throwing and Catching Errors....83
Types of Errors....85
Standard Errors....85
System Errors....87
Custom Errors....89
Layered Error Management....91
Debugging in Node....94
Preventive Measures....96
Code Quality Tools....96
Immutable Objects....96
Testing....97
Code Reviews....97
Summary....97
5. Package Management....99
Introducing Package Management....99
The npm Command....102
Semantic Versioning....108
Updating and Removing Packages....109
Creating and Publishing Packages....113
npm Run Scripts....115
The npx Command....117
Summary....119
6. Streams....121
Introducing Streams....121
Using Streams....123
Fundamentals of Streams....126
The pipeline Method....127
Stream Events....129
Paused and Flowing Modes....130
Implementing Streams....131
Writable Streams....131
Readable Streams....132
Duplex/Transform Streams....135
Async Generators and Iterators....137
Streams Object Mode....139
Built-In Transform Streams....141
Summary....142
7. Child Processes....143
Introducing Child Processes....143
The spawn Function....144
Shell Syntax and the exec Function....147
The execFile Function....150
The fork Function....150
Summary....153
8. Testing Node....155
Assertions and Runners....155
Types of Tests....160
Unit Tests....161
Functional Tests....161
Integration Tests....162
End-to-End Tests....162
Test Doubles....163
Organizing and Filtering Tests....169
Test-Driven Development....170
Continuous Integration....171
Summary....172
9. Scaling Node....175
Strategies of Scalability....175
The Cluster Module....176
Primary and Worker Processes....178
Broadcasting Messages....182
Increasing Availability....185
Zero-Downtime Restarts....187
Table of Contents | v
Handling State....191
Process Managers....192
Summary....193
10. Practical Node....195
Code Quality Tools....195
Prettier....197
ESLint....198
Other Tools....199
Module Bundlers....200
Task Runners....203
Frameworks....205
JavaScript Transpilers....209
TypeScript....210
Summary....216
Index....217
Take your web development skills from browser to server with Node.js, the popular backend framework used by more than 10 million developers at companies like Amazon, Netflix, and LinkedIn, to name just a few. If you're comfortable working with JavaScript, this practical guide from Samer Buna will show you how to effectively build and maintain even the most complex Node.js applications.
Following a hands-on, project-based approach, you'll move from key fundamentals to advanced concepts such as modules, packages, event-driven architecture, streams, child processes, scaling, testing, deployment, and much more—all while focusing on what actually matters in practice.
Understand Node.js's native capabilities in order to best use the powerful libraries and tools in its ecosystem
Utilize Node.js modules and packages
Explore Node.js's event-driven architecture, streams, and child processes
Create, test, and maintain efficient and scalable Node.js applications