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 🙏

© 2025 – Pkg Stats / Ryan Hefner

error-express-handler

v1.0.7

Published

Easy to use npm package of catching the most common error in nodejs

Readme

A graceful error handler for Express applications

npm npm NPM

Easy Express error handler with the most common errors

Error-Express-Handler is a easy middleware with build in errors messages for the most commun http errors in an express application. Using this package the user no longer have to put the code status and the message for the error

Getting started

  • npm install npm i error-express-handler or yarn add error-express-handler
  • In your express server file, require errorHandler
const { errorHandler } = require("error-express-handler");
const express = require("express");

//server
const server = expresss();
server.use(express.json());

//use errorHandler middleware here
server.use(errorHandler);

server.listen(port, () => {
  console.log(`\n*** Server running on http://localhost:${port}  ***\n`);
});

Whow it works

  • Example before using error-express-handler your code could look similar to:
router.delete("/users/:id", async (req, res, next) => {
  const { id } = req.params;
  try {
    const result = await dbHelpers.deleteUserById(id);
    if (result === 1) {
      res.status(200).json({
        message: "Delete user Sucesfully"
      });
    } else {
      res
        .status(404)
        .json({ message: "The server can not find requested resource" });
    }
  } catch (error) {
    res.status(500).json({
      error: `The server has encountered a situation it doesn't know how to handle`
    });
  }
});

Now you can require responseStatus anywhere in your code and use it like in this example:

const { responseStatus } = require("error-express-handler");

router.delete("/users/:id", async (req, res, next) => {
  const { id } = req.params;
  try {
    const result = await dbHelpers.deleteUserById(id);
    if (result === 1) {
      res.status(responseStatus.successful).json({
        message: "Delete user Sucesfully"
      });
    } else {
      next(responseStatus.notFound);
    }
  } catch (error) {
    next(responseStatus.serverError);
  }
});

The above would return:

  • in case of next(responseStatus.notFound):
{
  "statusCode": 404,
  "error": "The server can not find requested resource"
}
  • in case of next(responseStatus.serverError):
{
  "statusCode": 500,
  "error": "The server has encountered a situation it doesn't know how to handle"
}

For now this are all HTTP response status codes with detail error messages:

  successful: 200,
  created: 201,
  badRequest: 400,
  badCredentials: 401,
  forbiddenAccess: 403,
  notFound: 404,
  requestTimeout: 408,
  gone: 410,
  typeError: 422,
  serverError: 500,
  notImplemented: 501,
  badGateway: 502,
  serviceTemporarilyUnavaible: 503,
  gatewayTimeout: 504

Contribution

  • Wanna add more HTTP response status codes or got an idea on how to improve this error handler , feel free to contribute

Github repository @Sorin Chis