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

cubeforall-dbconnection

v1.1.4

Published

A centralized MongoDB connection handler with connection pooling and graceful shutdown support.

Downloads

52

Readme

CubeforAll MongoDB Connection Wrapper 🚀 A standardized wrapper to handle multiple MongoDB Atlas connections (with Mongoose or native driver) easily, ensuring your company never directly uses mongoose or mongodb libraries.

📦 Installation

npm install cubeforall-dbconnection 🔧 Features 🔌 Multiple Database Connections (e.g., platformMongo, boxMongo)

♻️ Connection Pooling & Reuse

✅ Graceful Shutdown Handling

🏗️ Schema Export (Mongoose) Ready

🚀 Native MongoDB Methods & Mongoose Compatibility

🌐 Usage Example 1️⃣ Connection Setup

=============================================

MongoDB

const express = require('express'); const bodyParser = require('body-parser'); const { connectMongoDB, closeAllConnections } = require('cubeforall-dbconnection'); const userController = require('./controllers/user.controller');

const app = express(); app.use(bodyParser.json());

// Initialize multiple connections at startup (async () => { await connectMongoDB('platformMongo', process.env.PLATFORM_MONGO_URI); await connectMongoDB('boxMongo', process.env.BOX_MONGO_URI); })();

// Routes: pass db name to controller app.get('/platform/users', (req, res) => userController.getUsers(req, res, 'platformMongo')); app.get('/box/users', (req, res) => userController.getUsers(req, res, 'boxMongo'));

process.on('SIGINT', async () => { await closeAllConnections(); process.exit(); });

app.listen(3000, () => console.log('🚀 Server running on port 3000'));

============================================= Mongoose

const express = require('express'); const bodyParser = require('body-parser'); const { connectToMongoAtlas, getConnection, closeAllConnections, } = require('cubeforall-dbconnection'); const { createUserHandler, getUsersHandler } = require('./controllers/user.controller');

const app = express(); app.use(bodyParser.json());

// Initialize Multiple Connections (async () => { await connectToMongoAtlas('platformMongo', process.env.PLATFORM_MONGO_URI); await connectToMongoAtlas('boxMongo', process.env.BOX_MONGO_URI); })();

// Routes Example app.post('/platform/users', async (req, res) => { const conn = getConnection('platformMongo'); await createUserHandler(req, res, conn); });

app.get('/box/users', async (req, res) => { const conn = getConnection('boxMongo'); await getUsersHandler(req, res, conn); });

// Graceful Shutdown process.on('SIGINT', async () => { await closeAllConnections(); process.exit(); });

app.listen(3000, () => console.log('🚀 Server running on port 3000')); 2️⃣ Schema Example (Mongoose) Inside models/user.model.js:

const mongoose = require('mongoose');

const userSchema = new mongoose.Schema({ name: { type: String, required: true }, email: { type: String, required: true, unique: true }, age: Number, }, { timestamps: true });

// Export function that binds schema to specific connection function getUserModel(connection) { return connection.model('User', userSchema); }

module.exports = { getUserModel }; 3️⃣ Service Example Inside services/user.service.js:

const { getUserModel } = require('../models/user.model');

async function createUser(connection, userData) { const User = getUserModel(connection); const newUser = new User(userData); return await newUser.save(); }

async function getAllUsers(connection) { const User = getUserModel(connection); return await User.find({}); }

module.exports = { createUser, getAllUsers }; 4️⃣ Controller Example Inside controllers/user.controller.js:

const { createUser, getAllUsers } = require('../services/user.service');

async function createUserHandler(req, res, connection) { try { const user = await createUser(connection, req.body); res.status(201).json(user); } catch (err) { res.status(500).json({ error: err.message }); } }

async function getUsersHandler(req, res, connection) { try { const users = await getAllUsers(connection); res.json(users); } catch (err) { res.status(500).json({ error: err.message }); } }

module.exports = { createUserHandler, getUsersHandler }; 5️⃣ Graceful Shutdown Handling No extra setup needed—your package automatically handles:

process.on('SIGINT', async () => { await closeAllConnections(); process.exit(); }); 💡 Benefits ✅ Company-wide standard MongoDB access pattern

✅ No more direct usage of mongoose or mongodb

✅ Easy connection handling for multi-tenant systems

✅ Supports MongoDB Native and Mongoose Schema

📜 License MIT License

cube-dashboard-stable v1.0.11

support-multiple-stable v1.0.15

new-version v1.1.2

mongoose v1.1.3