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-mongoose

v1.0.6

Published

Backend mongoose for Beautinique project.

Readme

@beautinique/backend-mongoose

Mongoose connection management, health/state reporting, and transaction-aware Express middleware for Beautinique backend services.

Installation

npm install @beautinique/backend-mongoose

express is a peer dependency - only required for checkDbConnection/tryCatchSession. Install whichever version your service already uses.

Connection

import { connectDb, disconnectDB } from '@beautinique/backend-mongoose';

await connectDb({ uri: process.env.MONGO_URI!, enableGlobalCache: true });

// on shutdown
await disconnectDB();

Health & state

import { connectionState, getConnectionHealth, mongoEvents } from '@beautinique/backend-mongoose';

if (connectionState.isConnected()) {
  /* ... */
}

app.get('/health', (_req, res) => res.json(getConnectionHealth()));

mongoEvents.on('error', (error) => logger.error({ err: error }, 'MongoDB error'));

checkDbConnection

Rejects requests with a ServiceUnavailableError (503) if the MongoDB connection isn't ready yet, instead of letting the request sit in mongoose's own query buffer (bufferCommands, ~10s timeout by default) only to fail later with an opaque, generic 500.

import { checkDbConnection } from '@beautinique/backend-mongoose';

await connectDb({ uri: process.env.MONGO_URI! });

app.use(checkDbConnection());
app.use('/api', routes); // only reached once the DB is connected

| Option | Default | Description | | --------- | -------------------------------------- | -------------------------------------------------- | | message | Database connection is not ready. | Overrides the ServiceUnavailableError message. |

Register it after connectDb() has been called, but before any route that touches the database - not in front of a health/readiness endpoint, which needs to report "not ready" rather than fail outright while the DB is still connecting.

tryCatchSession

Wraps an async Express route handler in a mongoose transaction, plus a deferred-lifecycle-hook pattern via res.locals - the database-backed counterpart to tryCatchResponse from @beautinique/backend-response.

import { tryCatchSession } from '@beautinique/backend-mongoose';

app.post(
  '/orders',
  tryCatchSession(async (req, res, next, session) => {
    const order = await orderService.create(req.body, { session });

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

    res.success({ data: order, statusCode: 201 });
  }),
);
  • Starts a session and transaction before calling the handler, which receives the active ClientSession as its 4th argument.
  • Commits the transaction if the handler resolves, aborts it if the handler throws/rejects - the abort itself is guarded, so a failure aborting never masks the original error.
  • Always ends the session afterwards, success or failure.
  • res.locals.afterCommit - run after the transaction commits.
  • res.locals.afterRollback - run after the transaction is aborted.
  • res.locals.afterResponse - also run after the transaction commits (in addition to afterCommit), for hooks that don't care specifically about the database.
  • res.locals.afterFinish - always run once the HTTP response has fully finished sending.

Any thrown/rejected error is forwarded to next(error), so it flows through errorResponse from @beautinique/backend-response the same way as everywhere else. For database-less services, use tryCatchResponse instead.

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.