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

@ashkiani/express-responses

v1.0.0

Published

Reusable response helpers for Express APIs with integrated logging support — standardize your JSON/text replies and HTTP error handling with one module.

Readme

express-responses

Reusable response helpers for Express APIs with integrated logging support — standardize your JSON/text replies and HTTP error handling with one module.


@ashkiani/express-responses

Reusable HTTP response helpers for Express APIs — with optional structured logging.

This utility standardizes how your Express app sends JSON, text, and error responses. It also supports logging response details (e.g., status codes and payloads) when a log object is available.


📦 Installation

npm install @ashkiani/express-responses

🛠 Usage

  1. Import the module:
const resUtils = require('@ashkiani/express-responses');
  1. Use it in your route handlers:
app.get("/api/example", async (req, res) => {
    const logEntry = {
        requestId: "abc123",
        timestamp: new Date()
    };

    try {
        await resUtils.sendJsonResponse(res, 200, { message: "Success!" }, logEntry);
    } catch (err) {
        await resUtils.send500InternalError(res, logEntry);
    }

    // Optional: Save logEntry to DB
});

📘 API Reference

sendTextResponse(res, statusCode, message, logEntry?)

Sends plain text and, if a logEntry object is provided, logs the response.

sendJsonResponse(res, statusCode, jsonObj, logEntry?)

Sends JSON and logs it if a logEntry object is present.

send204NoContent(res, logEntry?)

Sends a 204 No Content response.


Predefined Error Responses

These are convenience wrappers for common error statuses:

| Function | Description | | ----------------------------- | --------------------------- | | send400BadReq() | Bad Request (400) | | send401UnAuth() | Unauthorized (401) | | send500InternalError() | Internal Server Error (500) | | send503ServiceUnavailable() | Service Unavailable (503) |

Each function accepts (res, logEntry?) and safely logs the response if logEntry is provided.


💡 Notes

  • Logging is optional. If logEntry is omitted, the function still works without throwing errors.
  • These helpers work well with any logging system — just ensure your logEntry object includes a response field if you want to store response details.
  • Compatible with @ashkiani/mongo-logger for full request-response auditing.

📄 License

MIT © Siavash Ashkiani