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-response-rest

v1.0.1

Published

A standardized HTTP response utility class for Express.js APIs

Readme

HttpResponse – Express Response Helper

A lightweight and consistent utility to send standardized HTTP responses in your Express.js applications.

✨ Features

  • ✅ Simple and consistent response format
  • 📦 Typed with TypeScript
  • ⚡ Fast integration with Express
  • 🔁 Built-in support for common status codes
  • 🧩 Optional metadata, headers, and error structure
  • 🧼 Cleaner controller logic using HttpResponse.send() base method

📦 Installation

npm install express-response-rest

If you're using TypeScript and want type support for express.Response, install the types:

npm install --save-dev @types/express

🔧 Usage

1. TypeScript:

import express, { Request, Response } from 'express';
import { responseMiddleware } from 'express-response-rest';

const app = express();

app.use(responseMiddleware); // initiate

app.get('/success', (req: Request, res: Response) => {
	res.success({
		message: 'Fetched successfully',
		data: { id: 1, name: 'Hitraa' },
	});
});

app.get('/error', (req: Request, res: Response) => {
	res.badRequest({
		message: 'Invalid input provided',
		errors: { email: 'Email is required' },
	});
});

1. JavaScript:

const express = require('express');
const { responseMiddleware } = require('express-response-rest');

const app = express();

app.use(responseMiddleware); // initiate

app.get('/success', (req, res) => {
	res.success({
		message: 'Fetched successfully',
		data: { id: 1, name: 'Hitraa' },
	});
});

app.get('/error', (req, res) => {
	res.badRequest({
		message: 'Invalid input provided',
		errors: { email: 'Email is required' },
	});
});

See detailed examples on usage page


🧱 Available Methods

| Method | HTTP Code | Use Case | | --------------------------- | --------- | ------------------------------------- | | res.success | 200 | Standard successful response | | res.created | 201 | Resource created successfully | | res.accepted | 202 | Request accepted for async processing | | res.noContent | 204 | No content returned (DELETE, etc.) | | res.badRequest | 400 | Invalid request data | | res.unauthorized | 401 | Unauthenticated request | | res.forbidden | 403 | Access forbidden | | res.notFound | 404 | Resource not found | | res.notAcceptable | 406 | Invalid request content format | | res.conflict | 409 | Duplicate or conflict error | | res.gone | 410 | Resource is no longer available | | res.unsupportedMediaType | 415 | Unsupported Media/Content-Type | | res.unprocessableEntity | 422 | Validation or semantic errors | | res.tooManyRequests | 429 | Rate limiting violation | | res.error | 500 | Internal server error | | res.notImplemented | 501 | Functionality is not implemented | | res.serviceUnavailable | 503 | Server maintenance or overload | | res.send | - | Express native send method |


🧾 Response Format

All JSON responses follow this structure:

{
  "status": "success" | "error",
  "message": "String message",
  "data": { /* optional data */ },
  "errors": { /* optional errors */ },
  "meta": { /* optional metadata */ },
  "timestamp": "ISO date string"
}

✍️ Type Definitions

interface ResponseOptions {
  message?: string;
  data?: any;
  meta?: any;
  errors?: any;
  headers?: Record<string, string>;
  statusCode?: number;
}

Use SuccessResponseOptions or ErrorResponseOptions to narrow the type when needed.


🛡 License

Released under the MIT License


👨‍💻 Author

Made with ❤️ by Harshal Khairnar
Founder, Hitraa Technologies
📧 [email protected]


💡 Tip

If you want to return raw text or HTML instead of JSON, use Express' res.send() or res.render() directly. This library is strictly for JSON-based API responses.