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

@beautinique/backend-response

v1.0.2

Published

Backend Request middleware for Beautinique project.

Readme

@beautinique/backend-response

Consistent Express response handling for Beautinique backend services - a JSON success envelope, centralized error handling, a branded 404, and an async route wrapper.

Installation

npm install @beautinique/backend-response

express is a peer dependency - install whichever version your service already uses.

Wiring it together

import { errorResponse, notFoundResponse, successResponse, tryCatch } from '@beautinique/backend-response';

app.use(successResponse()); // near the top, before routes

app.use('/api', routes); // routes use tryCatch(...) internally

app.use(notFoundResponse({ serveHtml: true })); // after routes
app.use(errorResponse()); // last

successResponse

Attaches res.success(...) - a consistent { success: true, message, data? } JSON response helper - to every request, so route handlers don't have to hand-build that envelope themselves.

app.use(successResponse());

app.get(
  '/users/:id',
  tryCatch(async (req, res) => {
    const user = await userService.findById(req.params.id);
    res.success({ data: user, message: 'User fetched' });
  }),
);

| Option | Default | Description | | ----------------- | --------- | ---------------------------------------------------------------------- | | defaultMessage | Success | Used whenever a res.success(...) call doesn't provide its own. |

data is omitted from the JSON body entirely when not provided, rather than being sent as null/undefined.

tryCatch

Wraps an async Express route handler so any thrown/rejected error is forwarded to next(error) instead of crashing the process or hanging the request, and gives the handler three deferred lifecycle hooks via res.locals:

  • res.locals.afterResponse - run after the handler resolves successfully.
  • res.locals.afterRollback - run if the handler throws/rejects.
  • res.locals.afterFinish - always run once the HTTP response has fully finished sending.
app.post(
  '/orders',
  tryCatch(async (req, res) => {
    const order = await orderService.create(req.body);

    res.locals.afterResponse?.push(async () => {
      await notifyWarehouse(order.id);
    });

    res.success({ data: order, statusCode: 201 });
  }),
);

Express-only, no database/session dependency - safe to use in any service, including one with no database at all (e.g. an API gateway).

notFoundResponse

Catch-all for requests that matched no route. Register it after every route, but before errorResponse - it turns "nothing else handled this request" into a NotFoundError and forwards it via next(error), so it flows through the same error path as everything else.

app.use(notFoundResponse({ serveHtml: true }));

| Option | Default | Description | | ----------- | ------------------------------------------- | -------------------------------------------------------------------------------------------------------------------- | | message | (req) => \Cannot ${req.method} ${req.originalUrl}`| Builds theNotFoundErrormessage. Only used whenserveHtmlis off, or the request doesn't look like a browser navigation. | |serveHtml|false | Serve Beautinique's branded HTML 404 page for requests that look like a real browser navigation (anAcceptheader that explicitly includestext/html). JSON API clients still get the usual NotFoundErrorerrorResponse` flow. |

errorResponse

The app's centralized error-handling middleware. Register it LAST, after every route and other middleware - Express only recognizes a 4-argument function as error-handling middleware, and only errors that reach the end of the chain (e.g. via next(error), as tryCatch/checkEmptyRequest/serviceAccess all do) end up here.

app.use(errorResponse());

Sends a { success: false, code, message, fieldErrors?, globalErrors? } JSON response, using the thrown error's own statusCode/code/message/fieldErrors/globalErrors when it's a trusted operational AppError - otherwise a generic 500, never leaking the real error's message to the client.

| Option | Default | Description | | -------------- | -------------------------------- | -------------------------------------------------------------------------------------------------- | | includeStack | process.env.IS_DEV === 'true' | Include the underlying error's stack trace in the JSON response. Must stay off in production. |

Repository

https://github.com/Nageshwar1997/BQ-Packages

Homepage

https://github.com/Nageshwar1997/BQ-Packages

Issues

https://github.com/Nageshwar1997/BQ-Packages/issues

Author

Nageshwar Pawar

License

This package is licensed under the MIT License. See the root LICENSE file for details.