express-async-errors
Simplify Express error handling by automatically passing thrown errors to `next()`.
express-async-errors
ExpressSimplify Express error handling by automatically passing thrown errors to `next()`.
Fit
Bundle (gzip)
453 B
822 B raw
Install size includes transitive dependencies. Bundle size is gzipped browser payload.
Freshness
The Problem
In Express, async route handlers and middleware must manually catch and forward errors to next(). Without this, thrown exceptions are silently lost or crash the app instead of hitting the error handler.
What It Does
express-async-errors monkey-patches Express so thrown or rejected promises in async functions automatically propagate to your error-handling middleware, eliminating boilerplate try/catch blocks in every route.
Installation
npm install express-async-errorsUsage Example
import "express-async-errors";
import express from "express";
const app = express();
app.get("/", async (req, res) => {
throw new Error("Something went wrong");
});
app.use((err, req, res, next) => {
res.status(500).send(err.message);
});
app.listen(3000);Related packages
Node.js body parsing middleware — populate `req.body` from JSON, urlencoded, text, and raw payloads.
compressionExpressHTTP response compression middleware for Express — gzip/deflate responses to reduce bandwidth and improve load times.
cookie-parserExpressCookie parsing middleware for Express — parse Cookie headers into `req.cookies` and support signed cookies for tamper detection.
corsExpressCORS middleware for Express — configure cross-origin resource sharing with a single line of code.
express-fileuploadExpressSimple Express middleware for handling `multipart/form-data` file uploads, built on Busboy.