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

api-response-utility

v1.0.0

Published

Standardized API response utility for Node.js apps

Downloads

2

Readme

📦 API Response Utility – Usage Guide

A lightweight utility to standardize API responses for Node.js/Express applications. This helps maintain consistent response formats for success and error handling across your backend services.


🚀 Installation

npm install api-response-utility

Importing

const {
  success,
  error,
  validationError,
  routeNotFound,
  notFound,
  unauthorized,
  forbidden,
  conflict,
  tooManyRequests,
  internalServerError
} = require('api-response-utility');

Success Response

res.status(200).json(success({ userId: 123 }, "User retrieved successfully"));

Output

{
  "success": true,
  "message": "User retrieved successfully",
  "data": {
    "userId": 123
  },
  "statusCode": 200
}

Error Responses

res.status(500).json(error("Something went wrong", 500));

Output

{
  "success": false,
  "message": "Something went wrong",
  "errors": [],
  "statusCode": 500
}

Validation Error

res.status(422).json(validationError([
  { field: "email", msg: "Invalid email address" }
]));

Output

{
  "success": false,
  "message": "Validation failed",
  "errors": [
    { "field": "email", "msg": "Invalid email address" }
  ],
  "statusCode": 422
}

Unauthorized

res.status(401).json(unauthorized("You must be logged in"));

Output

{
  "success": false,
  "message": "You must be logged in",
  "errors": [],
  "statusCode": 401
}

Forbidden

res.status(403).json(forbidden("Access denied to this resource"));

Output

{
  "success": false,
  "message": "Access denied to this resource",
  "errors": [],
  "statusCode": 403
}

Not Found

app.use((req, res) => {
  res.status(404).json(routeNotFound(req.originalUrl));
});

Output

{
  "success": false,
  "message": "User not found",
  "errors": [],
  "statusCode": 404
}

Route Not Found (Fallback Middleware)

app.use((req, res) => {
  res.status(404).json(routeNotFound(req.originalUrl));
});

Output

{
  "success": false,
  "message": "Route \"/unknown\" not found",
  "statusCode": 404
}

Conflict

res.status(409).json(conflict("Email already exists"));

Output

{
  "success": false,
  "message": "Email already exists",
  "errors": [],
  "statusCode": 409
}

Too Many Requests

res.status(429).json(tooManyRequests());

Output

{
  "success": false,
  "message": "Too many requests",
  "errors": [],
  "statusCode": 429
}

Internal Server Error

res.status(500).json(internalServerError());

Output

{
  "success": false,
  "message": "Internal server error",
  "errors": [],
  "statusCode": 500
}

Credits

Implementation (c) 2025 Gulam Ashraf. MIT LICENSE