Categories
Express Node.js

How does middleware work in Express?

5 min read Jump links The middleware pattern Middleware syntax The two types of middleware Plain middleware Error handling middleware Using middleware At the route level At the router level At the application level Wrapping up

Categories
Express Node.js

Send awesome structured error responses with Express

9 min read Jump links Introducing the ‘Problem Details for HTTP APIs’ specification Problem types and Problem details objects Example problem details response More details, clearer problems Breakdown of a problem details object How to send problem details responses with Express Define problem types and map them to JavaScript error classes Look up the problem details for an […]

Categories
Express Node.js

How to create an error handler for your Express API

7 min read Jump links Getting errors to error handler middleware Creating an error handler Error handler concerns Error handler middleware function Error handler helper functions Applying the error handler middleware Example error response Next steps Getting errors to error handler middleware Creating an error handler Error handler concerns Error handler middleware function Error handler helper functions Applying […]

Categories
Express Node.js

How to handle request validation in your Express API

9 min read Jump links Getting to grips with JSON Schema Why should I use JSON Schema and not validation library X? How to integrate validation with JSON schemas into your application Pulling it all together Wrapping things up Handy JSON Schema links

Categories
Express Node.js

How to send consistent error responses from your Express API

6 min read When you’re building an API with Express it can be difficult to know how to send consistent error responses. The framework doesn’t seem to provide any special features for this, so you’re left to figure it out on your own. At some point you’ll probably find yourself wondering if you’re doing it “the right way”.