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

express-throwable

v1.0.2

Published

Middlewares for async handlers and error handlers for Express.js framework.

Downloads

261

Readme

express-throwable

This package contains some lightweight middlewares for Express.js v4 which helps to use async handlers and handle errors if it was happened during request processing.

Requirements

There are no any dependencies for this package. This package compatible with Express.js v4 and required Node.js v14+. Implemented on ES7.

Do not use it with Express.js v5+.

Installation

NPM:

npm install express-throwable

PNPM:

pnpm add express-throwable

Usage

import { throwable, finalize, errorHandler } from 'express-throwable'
// omit other imports...

const app = express() // create express application
// omit app settings...

// add error handler
app.use(errorHandler((error, request, response) => { // this is optional
    // do something with error, for example add record to log
    const details = {
        error,
        url: request.originalUrl,
        params: request.params,
        query: request.query,
        headers: request.headers,
        body: request.body
    }
    logger.error('Error handled.', details)
    // by default response will get status code 500 automatically
    // but you can change this behavior
    response.status(503).end()
}))

// add another error handler
app.use(errorHandler((error, request, response) => {
    // it could be something like this:
    if (error instanceof MyCustomError) {
        // omit logic...
    }
}))

app.get('/feature/:id', throwable(async (request, response) => {
    // now your may don't care about exceptions
    response.status(200).json(await getFeature(request.params.id))
    // when exception is happened then it will be passed into error handlers
}))

// Keep in mind, each throwable handler is a final handler
// No more other middlewares can't handle request after throwable handler,
// except handler which can be passed into `finalize()`

// add last middleware to handle end of request
// it must be really last middleware, don't forget it
app.use(finalize((request, response) => {
    // do something when response is finished...
    // for example, release connections with database, etc
    // something like this:
    const { db } = request.locals
    db.release()
}))

// run server
app.listen(serverPort)

Middlewares

This package provides only three middlewares:

throwable(async (request, response) => { ... })

Use this to wrap you async handlers.

finalize(async (request, response) => { ... })

Use this for your finally code to release resources, and to execute an error handlers. It must be last middleware attached to your express application.

errorHandler(async (error, request, response) => { ... })

Use this to process an errors. Error handlers will called after callback, which you can pass into finalize().

License

MIT