npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2026 – Pkg Stats / Ryan Hefner

@tumblewader/express-auto-catch-router

v1.1.1

Published

Enhanced Express Router with automatic async/await error handling

Downloads

32

Readme

Express Auto Catch Router

npm version License: MIT npm downloads Test Coverage Dependencies Node.js Version

Express Auto Catch Router is an enhanced Express router that automatically wraps asynchronous route handlers. This allows you to write cleaner code without worrying about wrapping every async function with try/catch blocks to forward errors to Express's error-handling middleware.

Features

  • Automatic Error Handling: Wraps async/await route handlers so that any unhandled errors or promise rejections are automatically caught and passed to next().
  • Broad Method Coverage: Supports all HTTP methods (GET, POST, PUT, DELETE, etc.) as well as use, all, and param.
  • Easy Integration: Works seamlessly with your existing Express application without requiring modifications to your route handler signatures.
  • Robust Async Detection: Uses a reliable method to detect async functions ensuring only those functions are wrapped.
  • Router Options Support: Accepts all standard Express router options like caseSensitive, strict, and mergeParams.

Installation

Install via npm:

npm install @tumblewader/express-auto-catch-router

Or with yarn:

yarn add @tumblewader/express-auto-catch-router

Note: This package is compatible with Express 4.x versions only.

Usage

Replace your existing Express router with the enhanced router. For example:

const express = require('express');
const AsyncRouter = require('@tumblewader/express-auto-catch-router');

// Create an instance of the enhanced router
const router = new AsyncRouter().getRouter();

// Or with router options
const routerWithOptions = new AsyncRouter({
  caseSensitive: true,
  strict: true,
  mergeParams: true
}).getRouter();

// Define a route without manual try/catch handling:
router.get('/user/:id', async (req, res) => {
  // Any error thrown here will be automatically caught and passed to next()
  const user = await User.findById(req.params.id);
  if (!user) {
    throw new Error('User not found');
  }
  res.json(user);
});

// In your main app file
const app = express();
app.use('/api', router);

// Standard error-handling middleware
app.use((err, req, res, next) => {
  console.error(err);
  res.status(500).json({ error: err.message });
});

app.listen(3000, () => console.log('Server running on port 3000'));

API

AsyncRouter

constructor(options)

Creates a new instance of the enhanced router and automatically patches methods for async error handling.

Parameters:

  • options (Object, optional): Router options object that will be passed to Express's Router.
    • caseSensitive (Boolean): Enable case sensitivity, default: false
    • strict (Boolean): Enable strict routing, default: false
    • mergeParams (Boolean): Preserve req.params values from parent router, default: false

getRouter()

Returns the underlying Express router instance with async error handling automatically applied to all route methods.

Contributing

Contributions are welcome! If you encounter any issues or have suggestions for improvements, please open an issue or submit a pull request.

License

This project is licensed under the MIT License. See the LICENSE file for details.

Repository

GitHub: https://github.com/tumblewader/express-auto-catch-router