π§© What is express-catchify?
If youβve ever written this π repeatedly:
app.get("/", async (req, res, next) => {
try {
const data = await getData();
res.json(data);
} catch (err) {
next(err);
}
});
You know how boring and repetitive try/catch blocks can get.
So, I built express-catchify β a lightweight (less than 1KB!) helper that automatically catches async errors in your Express routes.
β‘ Why I built it
While learning Express, I noticed almost every project had the same pattern:
- A bunch of try/catch blocks everywhere
- Lots of repetitive next(err) calls
- Middleware getting messy
I wanted a cleaner, reusable, modern way to wrap async routes.
Something you just plug in and forget about.
π How to Install
Using npm:
npm install express-catchify
Or yarn:
yarn add express-catchify
π‘ How to Use
ES Module
import express from "express";
import catchify from "express-catchify";
const app = express();
app.get("/", catchify(async (req, res) => {
const data = await getData();
res.json(data);
}));
app.use((err, req, res, next) => {
res.status(500).json({ message: err.message });
});
CommonJS
const express = require("express");
const catchify = require("express-catchify").default;
const app = express();
app.get("/", catchify(async (req, res) => {
const data = await getData();
res.json(data);
}));
app.use((err, req, res, next) => {
res.status(500).json({ message: err.message });
});
π§ͺ Why itβs Useful
β
Removes repetitive try/catch blocks
β
Makes route handlers clean and readable
β
Works with any async middleware
β
100% tested with Vitest
β MIT licensed and open source
π¦ Check it Out
π GitHub β github express-catchify
π¦ npm β npm express-catchify
π¬ Feedback
Iβd love to hear your thoughts:
- Would you use something like this in a production environment?
- Do you have any suggestions for improving the developer experience (DX)?
- Should I make a TypeScript-first version?
Top comments (0)