Functional Design Patterns for Express.js
by Jonathan Lee Martin
Ready to design Node.js backends that scale elegantly with new features
and are a pleasure to maintain? Learn to apply functional programming
patterns that transcend Express.js—these ideas are found in
exceptional production codebases of all kinds. Whether you’re a seasoned
back-end developer, front-end developer or recent web boot camp
graduate, this step-by-step guide is for you.
This work was written and produced entirely by the author. We are proud to be distributing it.
eBook Formats:
Get all eBook formats here for $24.95 (USD)
Add to Cart
Express is arguably the ubiquitous library for building Node backends.
As of mid-2019, it is a dependency of 3.75 million codebases on Github
alone. So if you hop into a Node codebase, chances are Express is part
of it.
Starting from an empty directory, we’ll build a full-featured Express
backend together and intentionally bump into codebase growing pains to
motivate functional design patterns and Express features. With this
book, you’ll:
- Learn Express.js by building a pure backend with authentication
from scratch.
- Apply best practices to architect resilient, testable Node.js
backends.
- Expand your design palate with functional design patterns that
transfer to any tech stack.
- Demystify key web abstractions by deriving each layer yourself,
then abstracting it away.
Based on real-world consulting experiences, this book features a
razor-focused set of topics and tools you’ll actually use, without
introducing any simplistic “code smells” or bad habits.
So whether you’re a seasoned back-end developer, front-end developer or
recent web boot camp graduate, this step-by-step guide will help you
develop exceptional Node backends that will outlive Express and expand
your design palate with functional programming patterns for any tech
stack.
What You Need
- Node 10 or higher
- A text editor
Resources
Releases:
- Acknowledgments
- Introduction
- Why Express?
- Approach
- Topics
- Prerequisites
- Let’s Get Started
- Express Essentials
- How Servers Talk
- HTTP: The Core Abstraction of the Web
- Installing telnet
- An HTTP Conversation with telnet
- Talking to a Backend API
- Making Requests with Insomnia
- Go Further
- Responding to Requests
- Simple Servers with the http Module
- Speaking HTTP over Telnet
- Responding to Different Routes
- Hello, Express
- Express Shorthands
- Go Further
- Express Router
- Refactoring with the Router Pattern
- Express
Router
- Functions with Methods
- Routes with Dynamic Segments
- Using Multiple Routers
- Extracting Routers into Files
- Go Further
- Routing on the Accept Header
- Working with Request Bodies
- Request Body Lifecycle
- Reading Request Bodies
- Finishing Up the Create Endpoint
- Update and Delete
- Express .route() Method
- Go Further
- Middleware
- Middleware
- Cross Cutting with Middleware
- Passing Data to Routes
- Route Middleware
- Middleware is Everywhere
- Go Further
- Error Handling Middleware
- Common Middleware
- Logging with Morgan
- Body Parser
- Middleware Factories
- Compression
- Serving a Frontend
- File Uploads with Multer
- Serving Static Files with a Path Prefix
- Accepting Multiple Body Types
- Go Further
- URL Encoded Bodies
- PATCH Things Up
- MIME Types
- Authentication & Authorization
- Basic Authentication
- Authorization Header
- Handling Authentication with Middleware
- Graceful Global Middleware
- Requiring Authentication
- Creating a Middleware Factory
- Currying and Middleware Factories
- Go Further
- Authentication with JSON Web Tokens
- Proof of Verification
- JSON Web Tokens
- Issuing Tokens
- Signing Tokens
- Dissecting a Token
- Accepting JSON Web Tokens
- Dealing with Invalid Tokens
- Decoupling with Middleware Factories
- Go Further
- Authorization Design Patterns
- Adding Authorization to a Route
- Authorization Design Flaws
- Extracting Authorization to Middleware
- Policies and Enforcers
- Simplifying Policies
- Enforcing Policies with Exceptions
- Sustainable Security
- Go Further
- Enforce All the Things
- Private Attachments
- Index
Author
Jonathan Lee Martin is a globetrotting
educator, author and international
speaker with a passion for craft. He’s trained hundreds of
developers—from career switchers to senior devs at NASA and HP—in
immersive bootcamps. He also helps working web developers craft
exceptional code through his screencast series,
TL;DR. While waiting on npm
install
, he travels the world as a fine art landscape
photographer.