Take your Node.js knowledge to the next level

Design and implement production-grade Node.js applications using proven patterns and techniques

+60,000 Copies sold World wide

Translated in 8 languages

Rated 4.7 on Amazon

Perfected throughout 3 editions

What people say

Joe Karlsson's profile picture

Joe Karlsson Software Engineer at MongoDB

I've read basically every Node.js book ever published, and this is my personal favorite (and best) by far. Even months after reading all the way through this text, I still learn new things each time I browse through it. What can I say, this is a must for anyone writing code in Node. js. Everything in the book, including the code examples, are very useful in practice.

Gleb Bahmutov's profile picture

Gleb Bahmutov VP of Engineering at Cypress.io

Wow! This book ... is amazing. After many years of programming with JavaScript, I still have learnt so much from this book. It covers many topics relevant to large Node.js applications with ease, with many relevant code snippets making the material easily approachable. While not for beginners, it is a great book for anyone looking to take their JS applications to the higher level.

Radoslav Stankov's profile picture

Radoslav Stankov Head of engineering at ProductHunt

Node.js Design Patterns is an excellent resource for learning. I learned a lot of things that I thought I already knew. My favorite part is the Commonjs and ES6 import systems and a lot of the more advanced recipes.

Ire Aderinokun's profile picture

Ire Aderinokun VP Engineering at BuyCoin Africa

Node.js Design Patterns is a really in-depth look into the world of Node.js. Everything you ever wanted to know, and more! It’s very comprehensive, and gets into the details of how Node.js works. It’s a perfect book for anyone who already knows a bit about Node.js, and is looking to deepen their knowledge.

Ersel Aker's profile picture

Ersel Aker Co-founder & CTO at JustFulfil

Read through a few chapters of Node.js Design Patterns this morning. It's an excellent reference book covering everything from from the intricacies of the Node.js runtime to scaling your services to serve millions of users. Grabbed another copy for our engineering team to use as a study tool.

Mike Rourke's profile picture

Mike Rourke Software Engineer and Author

There is a lot of useful content in this book, and I think the title doesn't do it justice. If you want a comprehensive book about Node.js that not only acts as a reference for best practices and design patterns, but also as a one-stop shop for understanding how Node.js works behind the scenes, look no further!

Maya Shavin's profile picture

Maya Shavin Senior Frontend Engineer at Cloudinary

This book surprised me for how detailed it is! It contains a lot of useful and easy-to-understand information. For someone familiar with the Node.js, I'm intrigued by how much depth the book provides in working with Node.js. Every topic is approached in a very straightforward way: while being practical, this book offers different readers' levels - from the most juniors to the experienced ones - an excellent reference to apply design patterns in any real scale Node.js application. Totally going to bookmark it as my favorite Node.js book!

Kostas Bariotis's profile picture

Kostas Bariotis Software Engineer at Bulb

Node.js Design Patterns is an amazing resource for every level of Node.js developers. It covers important design patters that are used in the Node.js world (modules, callbacks, asynchronicity, etc) and explores critical bits of the core library (promises, streams, event emitters, etc). Finally, it provides best practices on running Node.js as part of a bigger architecture where you need to horizontally scale an application, balance the incoming load and setup a message bus in between your services.

David Wells's profile picture

David Wells Serverless architect & full-stack developer

If you want a deep dive into how Node.js works and the available design patterns, I'd recommend checking out Mario and Luciano's new book. I particularly enjoyed the section on using streams. After reading, I realized haven't been leveraging streams enough in my projects.

Simon Høiberg's profile picture

Simon Høiberg Freelance Software Engineer

Node.js Design Patterns is a great, in-depth resource for both beginners and advanced. Even though I've been writing Node.js applications for the past 5 years, I learned a lot from this comprehensive piece of work. By far the best Node.js book currently out there.

Mike Alche's profile picture

Mike Alche Node.js and React consultant

Every time a new Node.js book comes out I read it. I think there isn’t a single one that I haven’t read. And out of all of them I must say that Node.js Design Patterns is by far — and I mean it BY FAR— the undisputed best. To put it in the most honest way possible: this is the book I go to read when preparing to teach a Node.js class to groups of software engineers.

Theodore Vorillas's profile picture

Theodore Vorillas JavaScript Engineer at Workable

Node.js Design Patterns is a must read, an excellent resource for learning how to build Node.js applications. I loved the fact that you can actually learn new stuff regardless your experience. My favorite chapters are about scaling a production application (Universal JavaScript, Scalability and Architectural Patterns, Advanced Recipes)... and the coding samples are also available for free on GitHub!

Learn proven patterns, techniques, and tricks to take full advantage of the Node.js platform

Node.js Design Patterns book cover

Master well-known design principles to create modern applications that are readable, extensible, and that can grow big

This book will teach you how to implement a series of best practices and design patterns to create efficient and robust Node.js applications.

The first chapters of the book are designed to explore the basics of Node.js, analyzing its asynchronous event driven architecture and its fundamental design patterns including control flow patterns with callbacks, promises and async/await.

The second part of the book dives into Node.js streams and explores some of the most famous Gang of Four design patterns reinterpreted in the context of Node.js plus some original patterns that are specific to JavaScript and Node.js.

In the last section this book covers more advanced topics such as Universal JavaScript with Node.js, React and Webpack, best practices to scale Node.js services, microservices and messaging patterns for enterprise-grade distributed applications.

Throughout the book you will see Node.js in action with the help of several real-life examples leveraging great technologies such as LevelDB, Redis, RabbitMQ, ZeroMQ and many others. They will be used to demonstrate a pattern or a technique, but they will also give you a great introduction to the Node.js ecosystem and its set of solutions.

What's in the book

Node.js Design Patterns is the book for software engineers who want to master Node.js and implement production applications with confidence.

150 Working examples & 50 exercises

With hundreds of working examples, you immediately put into practice everything you learn. Every code sample comes with a full step-by-step explanation, so you don't have to spend time to guess how things work. At the end of every chapter you will find engaging coding challenges to test your understanding of the various topics and gain more confidence with them.

13 Exquisitely crafted chapters

Every chapter will bring you one step closer to becoming a Node.js expert. From the basics of the Node.js architecture to how to scale and distribute your application, the book covers almost every aspect of professional Node.js development.

660 Pages packed with knowledge

A good learning experience can't be achieved by only throwing code and notions at the reader. Node.js Design Patterns comes with in-depth explanations and examples, so that even a novice can follow and immediately take advantage of advanced techniques.

Get the free chapter

Behavioural Design Patterns

With this 54 pages long chapter you will learn how to implement and leverage some of the most well known behavioural design patterns in the context of Node.js: the Strategy pattern, the State pattern, the Template pattern, the Iterator pattern, the Middleware pattern, and the Command pattern.

    Node.js Design Patterns chapter 9 behavioral design patterns

    Table of Contents

    Every chapter has been carefully crafted to explore and master a particular area of Node.js professional development.

    1. The Node.js Platform

      Learn about the Node.js philosophy, the reactor patterns and the differences between JavaScript on the browser and Node.js on the server.

    2. The Module System

      Learn how to leverage the powerful Node.js module system and discover the main differences between CommonJS and ESM.

    3. Callbacks and Events

      Discover the callback pattern, how it works and the conventions used in Node.js. Learn how to avoid pitfalls and when to take advantage of the observer pattern using Node.js built-in event emitter.

    4. Asynchronous Control Flow Patterns with Callbacks

      Lean how to avoid callback hell and explore common asynchronous patterns such as sequential execution, sequential iteration, parallel execution and limited parallel execution.

    5. Asynchronous Control Flow Patterns with Promises and Async/Await

      Find out how promises work and how to use them effectively to implement various asynchronous control flow patterns. Explore the modern async/await syntax, the main tool today for dealing with asynchronous code in Node.js

    6. Coding with Streams

      Understand why streams are so important in Node.js. Learn how to use standard streams and how to create custom ones. Explore various streaming patterns and learn how to build powerful streaming pipelines.

    7. Creational Design Patterns

      Learn about the most famous creational design patterns in Node.js: the Factory pattern, the Revealing Constructor pattern, the Builder pattern. Finally, explore the Singleton pattern and the Dependency Injection pattern.

    8. Structural Design Patterns

      Discover how to implement and use the Proxy, the Decorator and the Adapter pattern in Node.js.

    9. Behavioural Design Patterns

      Learn how to implement and leverage some of the most well known behavioural design patterns in the context of Node.js: the Strategy pattern, the State pattern, the Template pattern, the Iterator pattern, the Middleware pattern, and the Command pattern.

      Free Chapter!

    10. Universal JavaScript

      Explore the fundamentals of JavaScript cross-platform development and learn how to share code between the browser and Node.js. Learn how to leverage React.js to build a complete universal JavaScript application.

    11. Advanced Recipes

      Discover well-known recipes to deal with some more advanced Node.js intricacies such as dealing with asynchronously initialized components, performing asynchronous request batching and caching, canceling asynchronous operations and running CPU-bound tasks.

    12. Scalability and Architectural Patterns

      Master the art of Node.js scalability by learning about the "Scale Cube", discover how to run multiple instances of the same application and how to use load balancers and service registers. Learn how to use containers and containers orchestration platforms such as Kubernetes. Finally, find out how to design and build microservices architectures.

    13. Messaging and Integration Patterns

      Learn how to integrate complex distributed Node.js applications using the most popular messaging systems. Learn how to implement the most common messaging patterns on top of ZeroMQ, RabbitMQ and Redis Streams.

    Meet the authors

    Meet Mario and Luciano, two passionate software engineers with a shared passion for Node.js and more than 20 years of collective experience on the field!

    Mario Casciaro

    Mario Casciaro's picture

    Mario is a software engineer and entrepreneur who worked at IBM for a number of years. He currently splits his time between Var7 Technologies (his own software company) and its role as Lead Engineer at D4H Technologies where he creates software for emergency response teams.

    Luciano Mammino

    Luciano Mammino's picture

    Luciano wrote his first line of code at the age of 12 on his father's old i386. Since then, he has never stopped coding. He is working at FabFitFun as Principal Software Engineer where he is building software to serve millions of users every day. He is an active speaker and in the last few years he has delivered more than 50 talks.

    Buy Node.js Design Patterns third edition

    Node.js Design Patterns third edition is available in Print and Kindle editions

    Buy Print edition Buy Kindle edition

    Mario Casciaro's picture

    FAQs

    This book is for developers and software architects who have some prior knowledge of JavaScript and Node.js and now want to get the most out of these technologies in terms of productivity, design quality, and scalability. Software professionals with intermediate experience in Node.js and JavaScript will also find valuable the more advanced patterns and techniques presented in this book.

    This book assumes that you have an intermediate understanding of JavasScript, web application development, databases, and software design principles. If you are new to JavaScript but you are familiar with other languages and technologies this book can still be a valuable resource for you but we do recommend you to get familiar with the basics of JavaScript first. Some good FREE resources you could check out are Eloquent JavaScript, JavaScript introduction by W3C and JavaScript in 30 days.

    This book will get you comfortable with writing asynchronous code by leveraging callbacks, promises, and the async/await syntax. It will teach you how to leverage Node.js streams to create data-driven asynchronous processing pipelines, how to implement well-known software design patterns to create production grade applications, and how to share code between Node.js and the browser, taking full advantage of full-stack JavaScript. Finally, this book will show you how to build and scale microservices and distributed systems powered by Node.js and how to use Node.js in conjunction with other powerful technologies such as Redis, RabbitMQ, ZeroMQ, and LevelDB.

    No. Node.js Design Patterns is the result of countless hours of hard work by the authors, the reviewers and many professionals at Packt, so we simply can't afford to give it away for free. If you want to have a feeling about the quality of the content in the book, you can download Chapter 9: Behavioural Design Patterns for FREE. You can also check out for FREE all the code examples available in the book on the official GitHub repository.

    The book has 13 chapters totaling about 660 pages.

    The book was written to give you continuity throughout the chapters so that you can enjoy reading the book from the first to the very last page. Although, if you are already familiar with many Node.js concepts and design patterns, you can easily skim through the chapters and focus only on the content that matters the most to you. Check out the Table of Contents if you want to have a better feeling on how the book is structured.

    The third edition of this book (released in July 2020) has been updated to cover the features of the most recent Node.js LTS version (Node.js 14). Node.js Design Patterns (third edition) leverages modern best practices and Node.js features such as Async/Await and EcmaScript Modules (ESM).

    All the code examples contained in the book are available on GitHub and can be accessed for FREE.

    Node.js Design Patterns provides a mix of simple examples and real-life applications to gradually introduce you to new topics and patterns. Some examples of real-life applications are:

    • Your own module loader
    • A website spider and downloader
    • A streaming file archive pipeline
    • A plugin for LevelUp
    • A full stack universal JavaScript website with Fastify, React and Webpack
    • A dynamic HTTP load balancer using Consul
    • A peer-to-peer network for web services
    • A distributed real-time chat application with an interactive web UI which leverages ZeroMQ, RabbitMQ and Redis Streams
    • A worker pool for background job executions using ZeroMQ, RabbitMQ and Redis Streams

    You can checkout the source code for these examples for FREE on GitHub.

    Every chapter comes with a set of engaging coding challenges and exercises crafted to put your new learnings into practice. Node.js Design Patterns contains 50 exercises in total.

    You are more than welcome to reach out to the authors on Twitter (@mariocasciaro and @loige) or you can write an email to [email protected].