express-async-errors

A one-line patch that lets Express route handlers throw or reject instead of manually calling next(err).

Library
npm
v3.1.1
905stars
ISC

Repository Health

Pre-computed score based on development activity, maintenance, community, maturity, and trend momentum.How we score it →
36/100Needs Attention
Development Activity0
Maintenance20
Community36
Maturity60
Momentum28

Technical Analysis

AI-assessed by reading the actual repository — architecture, code quality, innovation, and documentation.How we score it →
56/100Fair
Architecture55
Code Quality65
Innovation60
Learning Curve45

express-async-errors is a tiny compatibility patch for Express 4 that lets async route handlers and middleware propagate rejected promises straight to Express’s error-handling middleware. Instead of wrapping every async handler in a try/catch and manually calling next(err), you require the module once at startup and any thrown error or rejected promise inside a route, middleware, or app.param() callback is automatically forwarded to the next error handler.

Under the hood it works by redefining the handle property on Express’s internal Router Layer prototype, wrapping every handler function so that if it returns a promise, a .catch() is attached that calls next(err) with whatever error occurred. It also patches Router.param so async param handlers get the same treatment. The patch is applied once, in place, without touching any other part of Express, so the rest of the application uses express normally.

What You Get

  • Automatic promise rejection handling for async route handlers
  • Automatic error handling for async middleware, including error-handling middleware itself
  • Support for async app.param() callbacks
  • A single require() call with no configuration or API surface to learn

Common Use Cases

  • Simplifying async database queries in route handlers without try/catch boilerplate
  • Centralizing error handling in one Express error-handling middleware
  • Retrofitting an existing Express 4 app to support async/await safely
  • Building REST APIs where every handler is an async function

Under The Hood

Architecture The entire patch lives in a single file, index.js, with no internal layering: it redefines the handle property on Express’s internal Layer.prototype as a getter/setter, and wraps Router.prototype.constructor.param in a patchRouterParam() call. Every handler function assigned to a Layer’s handle property is transparently replaced with a wrapped version that captures the returned value, attaches a .catch(err => next(err)) if it looks like a promise, and copies the original function’s properties and length so Express’s internal arity checks (which decide whether a handler is a 4-arg error handler) still work. There is no exported API, no internal state beyond the one-time monkey-patch, and nothing would break by removing an abstraction because there isn’t one to begin with — the whole surface area is this one wrap function.

Tech Stack Plain CommonJS JavaScript with a peer dependency on express ^4.16.2 and no runtime dependencies of its own. Development tooling is ESLint with the airbnb-base config, Mocha for the test runner, supertest for HTTP assertions against a live Express app, and nyc for coverage reporting. There is no build step or transpilation — the published package is the raw source file.

Code Quality test.js covers the main paths with mocha + supertest: errors thrown in a route handler, errors thrown in regular async middleware, errors thrown inside an async error-handling middleware, errors thrown in an async app.param() callback, and a regression test asserting the router’s internal stack (including custom metadata attached by tools like Swagger generators) is preserved after patching. Given the library’s narrow scope this is reasonably thorough coverage relative to size, though there are no TypeScript types and error handling is implicit (a promise-shaped return value is duck-typed via ret.catch) rather than explicitly validated.

API Design There is effectively zero API surface — you require('express-async-errors') once before defining routes and everything else works exactly as vanilla Express. That absence of ceremony is the library’s main developer-experience strength: no wrapper functions to apply per-route, no need to change how handlers are written. The technique itself (monkey-patching Layer#handle) is borrowed from an earlier generator-based library (express-yields) rather than being a novel approach, and the same outcome is achievable natively in Express 5, which added built-in async error handling.

Used by 5 apps in this directory

JavaScript
100%
Other

Automatisch

Automation · No Code Platforms

13,964

Self-hosted, no-code workflow automation that keeps your data on your own servers—a privacy-first alternative to Zapier with 90+ integrations.

View details
49
Repo Health
78
Technical
63
Dependency
Built with
JavaScript100%
Updated 6 months ago
TypeScript
88%
MIT

Plasmic

CMS · Low Code Platforms · No Code Platforms

6,993

The open-source visual builder that lets teams design React apps and websites with drag-and-drop while integrating seamlessly with your codebase.

View details
81
Repo Health
78
Technical
64
Dependency
Built with
TypeScript88%
Updated yesterday
JavaScript
100%
AGPL 3.0

Social Analyzer

Security

23,945

Find and analyze a person's digital footprint across 1000+ social media platforms using multi-layer detection, OCR, and metadata extraction.

View details
42
Repo Health
52
Technical
68
Dependency
Built with
JavaScript100%
Updated 7 months ago
TypeScript
99%
Other

Sourcebot

Search · Developer Tools · AI Code Assistants

3,930

A self-hosted, AI-powered code search engine that indexes every repo across GitHub, GitLab, Bitbucket, Gitea, Gerrit, and Azure DevOps, so both engineers and coding agents can search, browse, and ask questions about your codebase from one place.

View details
85
Repo Health
83
Technical
65
Dependency
Built with
TypeScript99%
Updated 2 days ago
TypeScript
98%
Apache 2.0

Tianji

Analytics · Monitoring

3,086

Replace Google Analytics, UptimeKuma, and Prometheus with one self-hosted platform that tracks websites, monitors uptime, and reports server health.

View details
86
Repo Health
76
Technical
65
Dependency
Built with
TypeScript98%
Updated yesterday

Join founders buildingwith open source

Opinionated takes, migration guides, cost-saving tips, and insights from the open source ecosystem.

Subscribe on Substack
Join 750+ subscribers

Search