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

resify-express

v1.0.3

Published

<div align="center"> <h1>๐Ÿš€ resify-express</h1> <p><strong>The ultimate, elegant, and standardized response handler for Express.js APIs.</strong></p>

Readme

npm version License: ISC Node.js CI

Stop writing repetitive res.status(200).json(...) and res.status(500).json(...) across your entire Express application. resify-express provides a clean, consistent, and beautiful way to handle API responses and errors.

โœจ Features

  • ๐ŸŽฏ Standardized Responses: Consistent JSON structure for both success and error responses.
  • ๐Ÿ› ๏ธ Expressive Helpers: Injects .success() and .error() directly into the Express res object.
  • ๐Ÿšจ Custom Error Class: Built-in ApiError class for throwing structured HTTP errors.
  • ๐Ÿ›ก๏ธ Global Error Handler: Catch-all middleware to format unhandled exceptions beautifully.
  • ๐Ÿ› Developer Friendly: Optional stack trace inclusion for development environments.
  • ๐Ÿชถ Lightweight: Zero dependencies (except Express peer dependency).

๐Ÿ“ฆ Installation

Install the package using your favorite package manager:

npm install resify-express
# or
yarn add resify-express
# or
pnpm add resify-express

๐Ÿš€ Quick Start

Here is a minimal example to get you up and running in seconds.

const express = require("express");
const { attachHelpers, errorMiddleware, ApiError } = require("resify-express");

const app = express();
app.use(express.json());

// 1. Attach the response helpers (res.success, res.error)
app.use(attachHelpers);

// 2. Use the helpers in your routes
app.get("/users", (req, res) => {
  const users = [{ id: 1, name: "John Doe" }];
  
  // Beautiful success response
  return res.success(users, "Users fetched successfully", 200);
});

app.get("/users/:id", (req, res) => {
  const user = null; // Simulate not found

  if (!user) {
    // Throw structured errors easily
    throw new ApiError("User not found", 404, {
      code: "USER_NOT_FOUND",
      description: "No user exists with the provided ID",
    });
  }

  return res.success(user);
});

// 3. Add the global error middleware at the end
app.use(
  errorMiddleware({
    // Show stack traces only in development
    includeStack: process.env.NODE_ENV === "development", 
  })
);

app.listen(3000, () => console.log("Server running on port 3000 ๐Ÿš€"));

๐Ÿ“– API Reference

1. attachHelpers (Middleware)

Injects helper methods into the Express response (res) object.

res.success(data, message, status)

Sends a standardized success response.

  • data (any): The payload you want to return. Default: null.
  • message (string): A descriptive success message. Default: "Success".
  • status (number): HTTP status code. Default: 200.

Output:

{
  "success": true,
  "message": "Users fetched successfully",
  "data": [{ "id": 1, "name": "John Doe" }]
}

res.error(errorDetails, status, message)

Sends a standardized error response manually.

  • errorDetails (object): Object containing code, description, or error.
  • status (number): HTTP status code. Default: 500.
  • message (string): A descriptive error message. Default: "Error".

Output:

{
  "success": false,
  "message": "Validation Failed",
  "error": {
    "code": "INVALID_INPUT",
    "description": "Email is required"
  }
}

2. ApiError (Class)

A custom Error class designed specifically for HTTP APIs. When thrown, it is automatically caught and formatted by the errorMiddleware.

throw new ApiError("Unauthorized Access", 401, {
  code: "AUTH_FAILED",
  description: "Invalid or expired token provided."
});

Parameters:

  • message (string): The main error message.
  • status (number): HTTP status code.
  • options (object): Additional details { code, description }.

3. errorMiddleware(options)

A global Express error handler that catches ApiError instances and unhandled exceptions, formatting them into the standardized response structure.

Options:

  • includeStack (boolean): If true, includes the error stack trace in the response. โš ๏ธ Warning: Only set this to true in development to avoid exposing sensitive internal logic in production.

Example Output (Production):

{
  "success": false,
  "message": "User not found",
  "data": null,
  "error": {
    "code": "USER_NOT_FOUND",
    "description": "No user exists with the provided ID"
  }
}

Example Output (Development with includeStack: true):

{
  "success": false,
  "message": "User not found",
  "data": null,
  "error": {
    "code": "USER_NOT_FOUND",
    "description": "No user exists with the provided ID",
    "stack": "ApiError: User not found\n    at /app/src/routes.js:42:11..."
  }
}

๐Ÿค Contributing

Contributions, issues, and feature requests are welcome! Feel free to check the issues page.

  1. Fork the project
  2. Create your feature branch (git checkout -b feature/AmazingFeature)
  3. Commit your changes (git commit -m 'Add some AmazingFeature')
  4. Push to the branch (git push origin feature/AmazingFeature)
  5. Open a Pull Request

๐Ÿ“ License

This project is licensed under the ISC License.