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

exnexus

v1.1.0

Published

Production-ready Express utilities for error handling, logging, responses, and optional MongoDB connection helpers

Readme

exnexus 🚀

exnexus is a lightweight, production-ready utility belt for Node.js Express applications. It provides the core backend essentials every API needs: centralized error handling, structured responses, request logging, semantic error creators, and optional MongoDB connection helpers.


npm license node-current


✨ Features

  • asyncHandler: Eliminate repetitive try/catch blocks in async controllers.
  • responseEnhancer: Add expressive helpers like res.success(), res.created(), res.fail(), and more.
  • errors Utility: Create semantic HTTP errors like errors.notFound() or errors.badRequest().
  • requestLogger: Log HTTP requests with method, URL, status, and response duration.
  • ApiError & ApiResponse: Standardized JSON contracts for errors and successful responses.
  • errorHandler: Global middleware for formatting and handling errors consistently.
  • connectDB: Optional MongoDB connection helper for Mongoose users.

📦 Installation

Core package

npm install exnexus

With MongoDB support

npm install exnexus mongoose

mongoose is an optional peer dependency and is only needed if you use connectDB().


⚡ Quick Start

1. Initialize Global Middleware

import express from "express";
import { responseEnhancer, requestLogger, errorHandler } from "exnexus";

const app = express();

app.use(express.json());
app.use(requestLogger);
app.use(responseEnhancer);

// ... your routes ...

app.use(errorHandler);

2. Write Clean Controllers

import { asyncHandler, errors } from "exnexus";

export const getProfile = asyncHandler(async (req, res) => {
  const user = await User.findById(req.user._id);

  if (!user) {
    throw errors.notFound("User not found");
  }

  return res.success(user, "Profile retrieved successfully");
});

3. Optional MongoDB Connection

import express from "express";
import {
  connectDB,
  responseEnhancer,
  requestLogger,
  errorHandler,
} from "exnexus";

const app = express();

await connectDB({
  uri: process.env.MONGO_URI,
  retries: 3,
  retryDelay: 3000,
});

app.use(express.json());
app.use(requestLogger);
app.use(responseEnhancer);

// ... routes ...

app.use(errorHandler);

app.listen(5000, () => {
  console.log("Server running on port 5000");
});

🧩 Response Helpers

res.success(data, "Fetched successfully");
res.created(data, "Created successfully");
res.fail("Something went wrong");

Example:

{
  "success": true,
  "message": "Fetched successfully",
  "data": {
    "id": 1
  }
}

❌ Error Handling Example

import { asyncHandler, errors } from "exnexus";

export const getUser = asyncHandler(async (req, res) => {
  const user = await User.findById(req.params.id);

  if (!user) {
    throw errors.notFound("User not found");
  }

  return res.success(user);
});

🛢️ MongoDB Helper

import { connectDB } from "exnexus";

await connectDB({
  uri: process.env.MONGO_URI,
  retries: 3,
  retryDelay: 5000,
  exitOnFailure: true,
});

Options

| Option | Type | Default | Description | | ---------------- | -------- | --------------------- | --------------------------- | | uri | string | process.env.MONGO_URI | MongoDB connection string | | options | object | {} | Mongoose connection options | | retries | number | 3 | Retry attempts | | retryDelay | number | 5000 | Delay between retries | | exitOnFailure | boolean | true | Exit process on failure | | logger | object | console | Logger instance | | onConnected | function | - | Callback on connect | | onError | function | - | Callback on error | | onDisconnected | function | - | Callback on disconnect |


📂 Project Structure

src/
├── db/
├── middlewares/
├── utils/
└── index.js

⚙️ Environment Variables

| Variable | Description | Default | | --------- | ------------------------ | ---------- | | NODE_ENV | Show stack traces in dev | production | | LOG_LEVEL | Logging level | info | | MONGO_URI | Mongo connection string | - |


🧪 Testing

npm test

🤝 Contributing

PRs, issues, and ideas are welcome.

GitHub: https://github.com/FenilP07/Express-Toolkit


💬 Support

Open an issue for help or questions.


📄 License

MIT License